
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>相关代码 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../server/服务器部分.html" />
    
    
    <link rel="prev" href="音视频第三方库.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../doc/常用网站.html">
            
                <a href="../doc/常用网站.html">
            
                    
                    常用网站
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../常用软件/常用软件和框架.html">
            
                <a href="../常用软件/常用软件和框架.html">
            
                    
                    常用软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../doc/开发规范.html">
            
                <a href="../doc/开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../doc/开源软件.html">
            
                <a href="../doc/开源软件.html">
            
                    
                    开源软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../doc/Android常用代码.html">
            
                <a href="../doc/Android常用代码.html">
            
                    
                    Android常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../源码阅读/源码阅读配置.html">
            
                <a href="../源码阅读/源码阅读配置.html">
            
                    
                    源码阅读
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../源码阅读/其他框架源码.html">
            
                <a href="../源码阅读/其他框架源码.html">
            
                    
                    其他框架源码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../产品经理/产品经理.html">
            
                <a href="../产品经理/产品经理.html">
            
                    
                    产品经理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../设计模式/模式详解.html">
            
                <a href="../设计模式/模式详解.html">
            
                    
                    模式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../设计模式/mvc等.html">
            
                <a href="../设计模式/mvc等.html">
            
                    
                    mvc等
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    基本算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    常用数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../常用算法/算法术语.html">
            
                <a href="../常用算法/算法术语.html">
            
                    
                    算法术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../常用算法/排序算法.html">
            
                <a href="../常用算法/排序算法.html">
            
                    
                    排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../常用算法/查找算法.html">
            
                <a href="../常用算法/查找算法.html">
            
                    
                    查找算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../常用算法/大数相加.html">
            
                <a href="../常用算法/大数相加.html">
            
                    
                    大数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../常用算法/集合的所有子集.html">
            
                <a href="../常用算法/集合的所有子集.html">
            
                    
                    获得集合的所有子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../常用算法/扫描线种子填充算法.html">
            
                <a href="../常用算法/扫描线种子填充算法.html">
            
                    
                    扫描线种子填充算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../常用算法/其他算法.html">
            
                <a href="../常用算法/其他算法.html">
            
                    
                    其他算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    Java部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    原码补码反码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../java基础/java常用代码.html">
            
                <a href="../java基础/java常用代码.html">
            
                    
                    java常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../java基础/JVM详解.html">
            
                <a href="../java基础/JVM详解.html">
            
                    
                    JVM详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../java基础/类加载机制.html">
            
                <a href="../java基础/类加载机制.html">
            
                    
                    类加载机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../java基础/内存模型.html">
            
                <a href="../java基础/内存模型.html">
            
                    
                    内存模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../java基础/GC机制.html">
            
                <a href="../java基础/GC机制.html">
            
                    
                    GC机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../java基础/对象内存布局.html">
            
                <a href="../java基础/对象内存布局.html">
            
                    
                    对象内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../java基础/继承多态.html">
            
                <a href="../java基础/继承多态.html">
            
                    
                    继承和多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../java基础/相等判断.html">
            
                <a href="../java基础/相等判断.html">
            
                    
                    相等判断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../java基础/Java容器类.html">
            
                <a href="../java基础/Java容器类.html">
            
                    
                    Java容器类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../java基础/Java枚举.html">
            
                <a href="../java基础/Java枚举.html">
            
                    
                    Java枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../java基础/自定义异常.html">
            
                <a href="../java基础/自定义异常.html">
            
                    
                    自定义异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../java基础/深度拷贝.html">
            
                <a href="../java基础/深度拷贝.html">
            
                    
                    深度拷贝
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../java基础/泛型详解.html">
            
                <a href="../java基础/泛型详解.html">
            
                    
                    泛型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../java基础/线程详解.html">
            
                <a href="../java基础/线程详解.html">
            
                    
                    线程详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../java基础/java注解.html">
            
                <a href="../java基础/java注解.html">
            
                    
                    注解详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../java基础/数据解析.html">
            
                <a href="../java基础/数据解析.html">
            
                    
                    数据解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../java基础/java8新特性.html">
            
                <a href="../java基础/java8新特性.html">
            
                    
                    Java8新特性
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../android基础/android零散知识.html">
            
                <a href="../android基础/android零散知识.html">
            
                    
                    Android部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../android基础/基础控件使用.html">
            
                <a href="../android基础/基础控件使用.html">
            
                    
                    基础控件使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../android基础/android零散知识.html">
            
                <a href="../android基础/android零散知识.html">
            
                    
                    Android零散知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../android基础/android坐标体系.html">
            
                <a href="../android基础/android坐标体系.html">
            
                    
                    Android坐标体系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../android基础/APP的启动流程.html">
            
                <a href="../android基础/APP的启动流程.html">
            
                    
                    APP启动流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../android基础/View加载流程.html">
            
                <a href="../android基础/View加载流程.html">
            
                    
                    View加载流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../android基础/事件分发机制.html">
            
                <a href="../android基础/事件分发机制.html">
            
                    
                    事件分发机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../android基础/控件绘制流程.html">
            
                <a href="../android基础/控件绘制流程.html">
            
                    
                    控件绘制流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.8" data-path="../android基础/常用shape.html">
            
                <a href="../android基础/常用shape.html">
            
                    
                    常用shape
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.9" data-path="../android基础/进程通信.html">
            
                <a href="../android基础/进程通信.html">
            
                    
                    进程通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.10" data-path="../通信方式/通信方式详解.html">
            
                <a href="../通信方式/通信方式详解.html">
            
                    
                    通信方式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.11" data-path="../android基础/Binder详解.html">
            
                <a href="../android基础/Binder详解.html">
            
                    
                    Binder详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.12" data-path="../android基础/Handler详解.html">
            
                <a href="../android基础/Handler详解.html">
            
                    
                    Handle详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.13" data-path="../android基础/Fragment详解.html">
            
                <a href="../android基础/Fragment详解.html">
            
                    
                    Fragment详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.14" data-path="../android基础/Activity详解.html">
            
                <a href="../android基础/Activity详解.html">
            
                    
                    Activity详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.15" data-path="../android基础/BroadcastReceiver.html">
            
                <a href="../android基础/BroadcastReceiver.html">
            
                    
                    BroadcastReceiver详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.16" data-path="../android基础/Service服务.html">
            
                <a href="../android基础/Service服务.html">
            
                    
                    Service详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.17" data-path="../android基础/动画详解.html">
            
                <a href="../android基础/动画详解.html">
            
                    
                    动画详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.18" data-path="../android基础/屏幕刷新机制.html">
            
                <a href="../android基础/屏幕刷新机制.html">
            
                    
                    屏幕刷新机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.19" data-path="../android基础/屏幕适配.html">
            
                <a href="../android基础/屏幕适配.html">
            
                    
                    屏幕适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.20" data-path="../android基础/图片加载详解.html">
            
                <a href="../android基础/图片加载详解.html">
            
                    
                    图片加载详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.21" data-path="../android基础/WebView详解.html">
            
                <a href="../android基础/WebView详解.html">
            
                    
                    WebView详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.22" data-path="../android基础/沉浸式.html">
            
                <a href="../android基础/沉浸式.html">
            
                    
                    沉浸式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.23" data-path="../android基础/相机模块.html">
            
                <a href="../android基础/相机模块.html">
            
                    
                    相机模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.24" data-path="../android基础/地图模块.html">
            
                <a href="../android基础/地图模块.html">
            
                    
                    地图模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.25" data-path="../android基础/Androidstudio插件开发.html">
            
                <a href="../android基础/Androidstudio插件开发.html">
            
                    
                    Androidstudio插件开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.26" data-path="../android基础/Apk插件化开发.html">
            
                <a href="../android基础/Apk插件化开发.html">
            
                    
                    Apk插件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.27" data-path="../android基础/App组件化开发.html">
            
                <a href="../android基础/App组件化开发.html">
            
                    
                    App组件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.28" data-path="../android基础/sdk开发.html">
            
                <a href="../android基础/sdk开发.html">
            
                    
                    sdk开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.29" data-path="../android基础/APP优化.html">
            
                <a href="../android基础/APP优化.html">
            
                    
                    APP优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.30" data-path="../android基础/项目参数配置.html">
            
                <a href="../android基础/项目参数配置.html">
            
                    
                    项目参数配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.31" data-path="../android基础/App发布.html">
            
                <a href="../android基础/App发布.html">
            
                    
                    App发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.32" data-path="../android基础/Android外挂.html">
            
                <a href="../android基础/Android外挂.html">
            
                    
                    Android外挂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.33" data-path="../android基础/Android字节码插桩.html">
            
                <a href="../android基础/Android字节码插桩.html">
            
                    
                    Android字节码插桩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.34" data-path="../android基础/智能家居.html">
            
                <a href="../android基础/智能家居.html">
            
                    
                    智能家居
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../python/python爬虫.html">
            
                <a href="../python/python爬虫.html">
            
                    
                    python爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../gradle/Groovy.html">
            
                <a href="../gradle/Groovy.html">
            
                    
                    Groovy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../kotlin/kotlin部分.html">
            
                <a href="../kotlin/kotlin部分.html">
            
                    
                    kotlin部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../flutter/flutter部分.html">
            
                <a href="../flutter/flutter部分.html">
            
                    
                    flutter部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="ccpp.html">
            
                <a href="ccpp.html">
            
                    
                    native部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="Linux.html">
            
                <a href="Linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="ccpp.html">
            
                <a href="ccpp.html">
            
                    
                    cCpp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="NDK.html">
            
                <a href="NDK.html">
            
                    
                    NDK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="系统编译剪裁.html">
            
                <a href="系统编译剪裁.html">
            
                    
                    系统编译剪裁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5" data-path="音视频.html">
            
                <a href="音视频.html">
            
                    
                    音视频
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.6" data-path="音视频第三方库.html">
            
                <a href="音视频第三方库.html">
            
                    
                    音视频第三方库
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.17.7" data-path="相关代码.html">
            
                <a href="相关代码.html">
            
                    
                    相关代码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../server/服务器部分.html">
            
                <a href="../server/服务器部分.html">
            
                    
                    服务器部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../webDev/web部分.html">
            
                <a href="../webDev/web部分.html">
            
                    
                    web部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../人工智能/人工智能相关概念.html">
            
                <a href="../人工智能/人工智能相关概念.html">
            
                    
                    人工智能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../面试真题/极飞.html">
            
                <a href="../面试真题/极飞.html">
            
                    
                    面试真题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >相关代码</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;"><b>1. </b>&#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;</a></li><ul><li><span class="title-icon "></span><a href="#surfaceview-&#x7ED8;&#x5236;&#x56FE;&#x7247;"><b>1.1. </b>SurfaceView &#x7ED8;&#x5236;&#x56FE;&#x7247;</a></li><li><span class="title-icon "></span><a href="#surfaceview-&#x8BBE;&#x7F6E;&#x5706;&#x89D2;"><b>1.2. </b>SurfaceView &#x8BBE;&#x7F6E;&#x5706;&#x89D2;</a></li><li><span class="title-icon "></span><a href="#audiorecord-&#x91C7;&#x96C6;&#x5E76;&#x4FDD;&#x5B58;pcm"><b>1.3. </b>AudioRecord &#x91C7;&#x96C6;&#x5E76;&#x4FDD;&#x5B58;PCM</a></li><li><span class="title-icon "></span><a href="#audiotrack-&#x64AD;&#x653E;pcm"><b>1.4. </b>AudioTrack &#x64AD;&#x653E;PCM</a></li><li><span class="title-icon "></span><a href="#pcm&#x8F6C;-wav"><b>1.5. </b>pcm&#x8F6C; wav</a></li><li><span class="title-icon "></span><a href="#wav-&#x8F6C;-pcm"><b>1.6. </b>wav &#x8F6C; pcm</a></li><li><span class="title-icon "></span><a href="#camera2-api-&#x9884;&#x89C8;&#x5E76;&#x83B7;&#x5F97;yuv&#x6570;&#x636E;"><b>1.7. </b>Camera2 API &#x9884;&#x89C8;&#x5E76;&#x83B7;&#x5F97;YUV&#x6570;&#x636E;</a></li><li><span class="title-icon "></span><a href="#mediamuxer-&#x5206;&#x79BB;-&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;"><b>1.8. </b>MediaMuxer &#x5206;&#x79BB; &#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;</a></li><li><span class="title-icon "></span><a href="#mediamuxer-&#x5C06;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6DF7;&#x5408;"><b>1.9. </b>MediaMuxer &#x5C06;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6DF7;&#x5408;</a></li><li><span class="title-icon "></span><a href="#mediacodec-&#x5E38;&#x7528;-api"><b>1.10. </b>MediaCodec &#x5E38;&#x7528; API</a></li><li><span class="title-icon "></span><a href="#mediacodec--camera--surfaceview--&#x9884;&#x89C8;&#x5E76;&#x4FDD;&#x5B58;-h264-&#x6587;&#x4EF6;"><b>1.11. </b>MediaCodec + camera + SurfaceView  &#x9884;&#x89C8;&#x5E76;&#x4FDD;&#x5B58; H264 &#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#camera--surfaceview--audiorecord-mediacodec--mediamuxer-&#x9884;&#x89C8;&#x5E76;&#x751F;&#x6210;-mp4&#x6587;&#x4EF6;"><b>1.12. </b>camera + SurfaceView + AudioRecord+ MediaCodec+  MediaMuxer &#x9884;&#x89C8;&#x5E76;&#x751F;&#x6210; mp4&#x6587;&#x4EF6;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;"><b>2. </b>&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;"><b>2.1. </b>&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;-avcodec"><b>2.2. </b>&#x904D;&#x5386; AVCodec</a></li><li><span class="title-icon "></span><a href="#&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><b>2.3. </b>&#x914D;&#x7F6E;&#x4FE1;&#x606F;</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;avinputformat"><b>2.4. </b>&#x904D;&#x5386;AVInputFormat</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;avoutputformat"><b>2.5. </b>&#x904D;&#x5386;AVOutputFormat</a></li><li><span class="title-icon "></span><a href="#&#x904D;&#x5386;-avfilter"><b>2.6. </b>&#x904D;&#x5386; AVFilter</a></li><li><span class="title-icon "></span><a href="#mp3-&#x8F6C;-aac"><b>2.7. </b>mp3 &#x8F6C; aac</a></li><li><span class="title-icon "></span><a href="#&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;"><b>2.8. </b>&#x97F3;&#x9891;&#x89E3;&#x7801; + &#x64AD;&#x653E;</a></li><li><span class="title-icon "></span><a href="#native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;"><b>2.9. </b>native ffmpeg &#x5B9E;&#x73B0;&#x89E3;&#x7801; &#xFF0C; native &#x5C42;&#x7684; opensl &#x5B9E;&#x73B0;&#x64AD;&#x653E;</a></li><li><span class="title-icon "></span><a href="#&#x64AD;&#x653E;&#x672C;&#x5730;mp4"><b>2.10. </b>&#x64AD;&#x653E;&#x672C;&#x5730;MP4</a></li><li><span class="title-icon "></span><a href="#ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;"><b>2.11. </b>ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;</a></li></ul></ul></div><a href="#&#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;"><a name="&#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;" class="anchor-navigation-ex-anchor" href="#&#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x97F3;&#x89C6;&#x9891;&#x76F8;&#x5173;&#x4EE3;&#x7801;</h1>
<h2 id="surfaceview-&#x7ED8;&#x5236;&#x56FE;&#x7247;"><a name="surfaceview-&#x7ED8;&#x5236;&#x56FE;&#x7247;" class="anchor-navigation-ex-anchor" href="#surfaceview-&#x7ED8;&#x5236;&#x56FE;&#x7247;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. SurfaceView &#x7ED8;&#x5236;&#x56FE;&#x7247;</h2>
<pre><code class="lang-text">SurfaceView surfaceView = findViewById(R.id.surface);
surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        Canvas canvas = surfaceHolder.lockCanvas();
        canvas.drawBitmap(bitmap, 0, 0, paint);
        surfaceHolder.unlockCanvasAndPost(canvas);
    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {   }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {  }
});
</code></pre>
<h2 id="surfaceview-&#x8BBE;&#x7F6E;&#x5706;&#x89D2;"><a name="surfaceview-&#x8BBE;&#x7F6E;&#x5706;&#x89D2;" class="anchor-navigation-ex-anchor" href="#surfaceview-&#x8BBE;&#x7F6E;&#x5706;&#x89D2;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. SurfaceView &#x8BBE;&#x7F6E;&#x5706;&#x89D2;</h2>
<pre><code class="lang-text">&#x901A;&#x8FC7; View &#x63D0;&#x4F9B;&#x7684;&#x51FD;&#x6570; setOutlineProvider &#x548C; setClipToOutLine &#x8BBE;&#x7F6E;&#x5706;&#x89D2;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4E3A;SurfaceView&#x8BBE;&#x7F6E;&#x6210;&#x5176;&#x4ED6;&#x5F62;&#x72B6;&#x3002; 
if(Build.VERSION.SDK_INT &gt; Build.VERSION_CODES.LOLLIPOP){ // 5.0 &#x4EE5;&#x4E0A;&#x7CFB;&#x7EDF;
    player.setClipToOutline(true); //  &#x5BF9;&#x4E8E;&#x89C6;&#x56FE;&#x524D;&#x666F;&#x8FDB;&#x884C;&#x88C1;&#x526A;
    player.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            Rect rect = new Rect();
            view.getGlobalVisibleRect(rect);
            int leftMargin = 0;
            int topMargin = 0;
            Rect selfRect = new Rect(leftMargin, topMargin, rect.right - rect.left - leftMargin, rect.bottom - rect.top - topMargin);
            float radius = getResources().getDimension(R.dimen.dimenSize_8) ;
            outline.setRoundRect(selfRect, radius);
        }
    }) ;
}
</code></pre>
<h2 id="audiorecord-&#x91C7;&#x96C6;&#x5E76;&#x4FDD;&#x5B58;pcm"><a name="audiorecord-&#x91C7;&#x96C6;&#x5E76;&#x4FDD;&#x5B58;pcm" class="anchor-navigation-ex-anchor" href="#audiorecord-&#x91C7;&#x96C6;&#x5E76;&#x4FDD;&#x5B58;pcm"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. AudioRecord &#x91C7;&#x96C6;&#x5E76;&#x4FDD;&#x5B58;PCM</h2>
<pre><code class="lang-text">   /**
    * &#x91C7;&#x6837;&#x7387;&#xFF0C;&#x73B0;&#x5728;&#x80FD;&#x591F;&#x4FDD;&#x8BC1;&#x5728;&#x6240;&#x6709;&#x8BBE;&#x5907;&#x4E0A;&#x4F7F;&#x7528;&#x7684;&#x91C7;&#x6837;&#x7387;&#x662F;44100Hz,
    * &#x4F46;&#x662F;&#x5176;&#x4ED6;&#x7684;&#x91C7;&#x6837;&#x7387;&#xFF08;22050, 16000, 11025&#xFF09;&#x5728;&#x4E00;&#x4E9B;&#x8BBE;&#x5907;&#x4E0A;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x3002;
    */
   public static final int SAMPLE_RATE_INHZ = 44100;

   /**
    * &#x58F0;&#x9053;&#x6570;&#x3002;CHANNEL_IN_MONO and CHANNEL_IN_STEREO.
    * &#x5176;&#x4E2D;CHANNEL_IN_MONO&#x662F;&#x53EF;&#x4EE5;&#x4FDD;&#x8BC1;&#x5728;&#x6240;&#x6709;&#x8BBE;&#x5907;&#x80FD;&#x591F;&#x4F7F;&#x7528;&#x7684;&#x3002;
    */
   public static final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;
   /**
    * &#x8FD4;&#x56DE;&#x7684;&#x97F3;&#x9891;&#x6570;&#x636E;&#x7684;&#x683C;&#x5F0F;&#x3002; ENCODING_PCM_8BIT, ENCODING_PCM_16BIT, and ENCODING_PCM_FLOAT.
    */
   public static final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
   private AudioRecord audioRecord = null;
   private boolean isRecording = false;

   public void onstart(View view) {
       // &#x4E00;&#x6B21;&#x8BFB;&#x53D6;&#x591A;&#x5C11;&#x5185;&#x5BB9;
       final int minBufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE_INHZ, CHANNEL_CONFIG, AUDIO_FORMAT);
       audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE_INHZ,  CHANNEL_CONFIG, AUDIO_FORMAT, minBufferSize);
       final byte data[] = new byte[minBufferSize];

       audioRecord.startRecording();
       isRecording = true;

       new Thread(new Runnable() {
           @SuppressWarnings(&quot;AlibabaAvoidManuallyCreateThread&quot;)
           @Override
           public void run() {
               FileOutputStream os = null;
               try {
                   File file = new File(Environment.getExternalStorageDirectory(), &quot;testttttttt.pcm&quot;);
                   os = new FileOutputStream(file);
               } catch (FileNotFoundException e) {
                   e.printStackTrace();
               }

               if (null != os) {
                   while (isRecording) {
                       Log.i(&quot;aivin&quot; ,&quot;&#x6B63;&#x5728;&#x5F55;&#x5236;&quot;) ;
                       int read = audioRecord.read(data, 0, minBufferSize);
                       // &#x5982;&#x679C;&#x8BFB;&#x53D6;&#x97F3;&#x9891;&#x6570;&#x636E;&#x6CA1;&#x6709;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#xFF0C;&#x5C31;&#x5C06;&#x6570;&#x636E;&#x5199;&#x5165;&#x5230;&#x6587;&#x4EF6;
                       if (AudioRecord.ERROR_INVALID_OPERATION != read) {
                           try {
                               os.write(data);
                           } catch (IOException e) {
                               e.printStackTrace();
                           }
                       }
                   }
                   try {
                       os.close();
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
               }
           }
       }).start();
   }
</code></pre>
<h2 id="audiotrack-&#x64AD;&#x653E;pcm"><a name="audiotrack-&#x64AD;&#x653E;pcm" class="anchor-navigation-ex-anchor" href="#audiotrack-&#x64AD;&#x653E;pcm"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. AudioTrack &#x64AD;&#x653E;PCM</h2>
<pre><code class="lang-text">AudioTrack&#x6709;&#x4E24;&#x79CD;&#x6570;&#x636E;&#x52A0;&#x8F7D;&#x6A21;&#x5F0F;
MODE_STREAM &#xFF1A;&#x901A;&#x8FC7;write&#x4E00;&#x6B21;&#x6B21;&#x628A;&#x97F3;&#x9891;&#x6570;&#x636E;&#x5199;&#x5230;AudioTrack&#x4E2D;&#x3002;&#x6BCF;&#x6B21;&#x90FD;&#x9700;&#x8981;&#x628A;&#x6570;&#x636E;&#x4ECE;&#x7528;&#x6237;&#x63D0;&#x4F9B;&#x7684;Buffer&#x4E2D;&#x62F7;&#x8D1D;&#x5230;AudioTrack&#x5185;&#x90E8;&#x7684;Buffer&#x4E2D;&#xFF0C;&#x8FD9;&#x5728;&#x4E00;&#x5B9A;&#x7A0B;&#x5EA6;&#x4E0A;&#x4F1A;&#x4F7F;&#x5F15;&#x5165;&#x5EF6;&#x65F6;&#x3002;&#x9002;&#x5408;&#x5927;&#x6587;&#x4EF6;&#x3002;

MODE_STATIC &#xFF1A;&#x628A;&#x6240;&#x6709;&#x6570;&#x636E;&#x901A;&#x8FC7;&#x4E00;&#x6B21;write&#x8C03;&#x7528;&#x4F20;&#x9012;&#x5230;AudioTrack&#x4E2D;&#x7684;&#x5185;&#x90E8;&#x7F13;&#x51B2;&#x533A;&#xFF0C;&#x540E;&#x7EED;&#x5C31;&#x4E0D;&#x5FC5;&#x518D;&#x4F20;&#x9012;&#x6570;&#x636E;&#x4E86;&#x3002;
&#x8FD9;&#x79CD;&#x6A21;&#x5F0F;&#x9002;&#x7528;&#x4E8E;&#x50CF;&#x94C3;&#x58F0;&#x8FD9;&#x79CD;&#x5185;&#x5B58;&#x5360;&#x7528;&#x91CF;&#x8F83;&#x5C0F;&#xFF0C;&#x5EF6;&#x65F6;&#x8981;&#x6C42;&#x8F83;&#x9AD8;&#x7684;&#x6587;&#x4EF6;&#x3002;
</code></pre>
<pre><code class="lang-text"> /**
  * &#x91C7;&#x6837;&#x7387;&#xFF0C;&#x73B0;&#x5728;&#x80FD;&#x591F;&#x4FDD;&#x8BC1;&#x5728;&#x6240;&#x6709;&#x8BBE;&#x5907;&#x4E0A;&#x4F7F;&#x7528;&#x7684;&#x91C7;&#x6837;&#x7387;&#x662F;44100Hz,
  * &#x4F46;&#x662F;&#x5176;&#x4ED6;&#x7684;&#x91C7;&#x6837;&#x7387;&#xFF08;22050, 16000, 11025&#xFF09;&#x5728;&#x4E00;&#x4E9B;&#x8BBE;&#x5907;&#x4E0A;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x3002;
  */
 public static final int SAMPLE_RATE_INHZ = 44100;
 /**
  * &#x8FD4;&#x56DE;&#x7684;&#x97F3;&#x9891;&#x6570;&#x636E;&#x7684;&#x683C;&#x5F0F;&#x3002; ENCODING_PCM_8BIT, ENCODING_PCM_16BIT, and ENCODING_PCM_FLOAT.
  */
 public static final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT;

 /**
  * &#x64AD;&#x653E;&#xFF0C;&#x4F7F;&#x7528;stream&#x6A21;&#x5F0F;
  */
 public void onplay(View view) {
     final int minBufferSize = AudioTrack.getMinBufferSize(SAMPLE_RATE_INHZ, AudioFormat.CHANNEL_OUT_MONO, AUDIO_FORMAT);
     final  AudioTrack   audioTrack = new AudioTrack(
             new AudioAttributes.Builder()
                     .setUsage(AudioAttributes.USAGE_MEDIA)
                     .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                     .build(),
             new AudioFormat.Builder().setSampleRate(SAMPLE_RATE_INHZ)
                     .setEncoding(AUDIO_FORMAT)
                     .setChannelMask(AudioFormat.CHANNEL_OUT_MONO)
                     .build(),
             minBufferSize,
             AudioTrack.MODE_STREAM,
             AudioManager.AUDIO_SESSION_ID_GENERATE);
     audioTrack.play();

     File file = new File(Environment.getExternalStorageDirectory(), &quot;testttttttt.pcm&quot;);
     try {
         final FileInputStream  fileInputStream = new FileInputStream(file);
         new Thread(new Runnable() {
             @Override
             public void run() {
                 try {
                     byte[] tempBuffer = new byte[minBufferSize];
                     while (fileInputStream.available() &gt; 0) {
                         int readCount = fileInputStream.read(tempBuffer);
                         if (readCount == AudioTrack.ERROR_INVALID_OPERATION ||  readCount == AudioTrack.ERROR_BAD_VALUE) {
                             continue;
                         }
                         if (readCount != 0 &amp;&amp; readCount != -1) {
                             audioTrack.write(tempBuffer, 0, readCount);
                         }
                     }
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
         }).start();

     } catch (IOException e) {
         e.printStackTrace();
     }
 }
</code></pre>
<h2 id="pcm&#x8F6C;-wav"><a name="pcm&#x8F6C;-wav" class="anchor-navigation-ex-anchor" href="#pcm&#x8F6C;-wav"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. pcm&#x8F6C; wav</h2>
<p>&#x5728;pcm&#x6570;&#x636E;&#x524D;&#x52A0;&#x4E0A;wav&#x6587;&#x4EF6;&#x5934;&#x5373;&#x53EF;</p>
<pre><code class="lang-text">https://www.jianshu.com/p/f7863638acbe
</code></pre>
<h2 id="wav-&#x8F6C;-pcm"><a name="wav-&#x8F6C;-pcm" class="anchor-navigation-ex-anchor" href="#wav-&#x8F6C;-pcm"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. wav &#x8F6C; pcm</h2>
<p>&#x53BB;&#x6389;&#x6587;&#x4EF6;&#x5934;&#x5373;&#x53EF;</p>
<pre><code class="lang-text">https://www.jianshu.com/p/3f80fb907bd5
</code></pre>
<h2 id="camera2-api-&#x9884;&#x89C8;&#x5E76;&#x83B7;&#x5F97;yuv&#x6570;&#x636E;"><a name="camera2-api-&#x9884;&#x89C8;&#x5E76;&#x83B7;&#x5F97;yuv&#x6570;&#x636E;" class="anchor-navigation-ex-anchor" href="#camera2-api-&#x9884;&#x89C8;&#x5E76;&#x83B7;&#x5F97;yuv&#x6570;&#x636E;"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. Camera2 API &#x9884;&#x89C8;&#x5E76;&#x83B7;&#x5F97;YUV&#x6570;&#x636E;</h2>
<pre><code class="lang-text">public class GetCameraActivity extends Activity {
    private Context context;
    private TextureView mPreviewView;
    private Handler mHandler;
    private Size mPreviewSize;
    private static final SparseIntArray ORIENTATIONS = new SparseIntArray();
    public ImageReader mImageReader;
    private CaptureRequest.Builder mCaptureRequest;
    /**
     *  0--&gt;&#x540E;&#x7F6E;&#x76F8;&#x673A;  1---&gt; &#x524D;&#x7F6E;&#x76F8;&#x673A;
     */
    private String mCameraId = &quot;1&quot;;


    @Override
    protected void onCreate( ... ) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_getcamera);
        context = this;

        ORIENTATIONS.append(Surface.ROTATION_0, 90);
        ORIENTATIONS.append(Surface.ROTATION_90, 0);
        ORIENTATIONS.append(Surface.ROTATION_180, 270);
        ORIENTATIONS.append(Surface.ROTATION_270, 180);

        mPreviewView = findViewById(R.id.textureview);
        mPreviewView.setSurfaceTextureListener(surfaceTextureListener);

        HandlerThread mThreadHandler = new HandlerThread(&quot;CAMERA2&quot;);
        mThreadHandler.start();
        mHandler = new Handler(mThreadHandler.getLooper());

    }


    private void startPreview(CameraDevice camera) throws CameraAccessException {
        try {
            // &#x8BF7;&#x6C42;&#x9884;&#x89C8;
            mCaptureRequest = camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }

        // &#x81EA;&#x52A8;&#x5BF9;&#x7126;
        mCaptureRequest.set(CaptureRequest.CONTROL_AF_MODE,  CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

        //&#x8BBE;&#x7F6E;&#x65B9;&#x5411;
        CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        //&#x6444;&#x50CF;&#x5934;&#x4F20;&#x611F;&#x5668;&#x65B9;&#x5411;
        int mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
        // &#x83B7;&#x53D6;&#x8BBE;&#x5907;&#x65B9;&#x5411;
        int rotation = getWindowManager().getDefaultDisplay().getRotation();
        // &#x6839;&#x636E;&#x8BBE;&#x5907;&#x65B9;&#x5411;&#x8BA1;&#x7B97;&#x8BBE;&#x7F6E;&#x6444;&#x50CF;&#x5934;&#x7684;&#x65B9;&#x5411;
        int value = (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
        mCaptureRequest.set(CaptureRequest.JPEG_ORIENTATION, value);

        // yuv&#x6570;&#x636E;&#x56DE;&#x8C03;
        mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(), ImageFormat.YUV_420_888, 2);
        mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mHandler);

        // &#x4F7F;&#x9884;&#x89C8;&#x548C;yuv&#x56DE;&#x8C03;&#x751F;&#x6548;
        SurfaceTexture texture = mPreviewView.getSurfaceTexture();
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        Surface surface = new Surface(texture);
        mCaptureRequest.addTarget(surface);
        mCaptureRequest.addTarget(mImageReader.getSurface());

        // &#x521B;&#x5EFA;&#x76F8;&#x673A;&#x6355;&#x83B7;&#x4F1A;&#x8BDD;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;&#x6355;&#x83B7;&#x6570;&#x636E;&#x7684;&#x8F93;&#x51FA;Surface&#x5217;&#x8868;&#xFF0C;
        // &#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x662F;CameraCaptureSession&#x7684;&#x72B6;&#x6001;&#x56DE;&#x8C03;&#x63A5;&#x53E3;&#xFF0C;&#x5F53;&#x5B83;&#x521B;&#x5EFA;&#x597D;&#x540E;&#x4F1A;&#x56DE;&#x8C03; onConfigured &#x65B9;&#x6CD5;
        // &#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x7528;&#x6765;&#x786E;&#x5B9A;Callback&#x5728;&#x54EA;&#x4E2A;&#x7EBF;&#x7A0B;&#x6267;&#x884C;&#xFF0C;&#x4E3A;null&#x7684;&#x8BDD;&#x5C31;&#x5728;&#x5F53;&#x524D;&#x7EBF;&#x7A0B;&#x6267;&#x884C;
        camera.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), mSessionStateCallback, mHandler);
    }

    /**
     * textureView &#x72B6;&#x6001; &#x56DE;&#x8C03;
     */
    TextureView.SurfaceTextureListener surfaceTextureListener = new TextureView.SurfaceTextureListener() {
        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
            try {
                CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
                //&#x83B7;&#x5F97;&#x6307;&#x5B9A;&#x6444;&#x50CF;&#x5934;&#x7684;&#x7279;&#x5F81;&#xFF0C;&#x652F;&#x6301;&#x7684;&#x53C2;&#x6570;
                CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(mCameraId);
                StreamConfigurationMap streamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                //&#x6444;&#x50CF;&#x5934;&#x652F;&#x6301;&#x7684;&#x9884;&#x89C8;Size&#x6570;&#x7EC4;
                List list = Arrays.asList(streamConfigurationMap.getOutputSizes(ImageFormat.YUV_420_888));

                Size size4 = new Size(640, 480);
                if (!list.contains(size4)) {
                    // &#x6839;&#x636E;TextureView&#x7684;&#x5C3A;&#x5BF8;&#x8BBE;&#x7F6E;&#x9884;&#x89C8;&#x5C3A;&#x5BF8;
                    mPreviewSize = streamConfigurationMap.getOutputSizes(SurfaceTexture.class)[0];
                } else {
                    mPreviewSize = size4;
                }

                for (String cameraId : cameraManager.getCameraIdList()) {
                    CameraCharacteristics characteristic
                            = cameraManager.getCameraCharacteristics(cameraId);
                    Integer facing = characteristic.get(CameraCharacteristics.LENS_FACING);
                    if (facing != null &amp;&amp; facing == CameraCharacteristics.LENS_FACING_BACK) {
                        mCameraId = cameraId;
                        break;
                    }
                }
                //&#x6253;&#x5F00;&#x76F8;&#x673A;
                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                cameraManager.openCamera(mCameraId, mCameraDeviceStateCallback, mHandler);
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        }

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
            return false;
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surface) {  }
    };


    /**
     * &#x76F8;&#x673A;&#x6253;&#x5F00;&#x72B6;&#x6001;&#x56DE;&#x8C03;
     */
    private CameraDevice.StateCallback mCameraDeviceStateCallback = new CameraDevice.StateCallback() {

        @Override
        public void onOpened(CameraDevice camera) {
            try {
                startPreview(camera);
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onDisconnected(CameraDevice camera) {
            camera.close();
        }

        @Override
        public void onError(CameraDevice camera, int error) {
            camera.close();
        }
    };

    /**
     * &#x6570;&#x636E;&#x56DE;&#x8C03;&#x63A5;&#x53E3;
     */
    private ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {
        @Override
        public void onImageAvailable(ImageReader reader) {
            Image image = reader.acquireNextImage();
            //YUV_420_888&#x683C;&#x5F0F; ----&gt;&#x83B7;&#x53D6;&#x5230;&#x7684;&#x4E09;&#x4E2A;&#x901A;&#x9053; getPlanes &#x5206;&#x522B;&#x5BF9;&#x5E94;YUV
            Image.Plane[] planes = image.getPlanes();
            ByteBuffer byteBufferY = planes[0].getBuffer() ;
            byte[] dataY = new byte[ byteBufferY.remaining()];
            byteBufferY.get(dataY) ;
            Log.i(&quot;aivin&quot; ,&quot;&#x6536;&#x5230;&#x6570;&#x636E;&#x56DE;&#x8C03; Y&#x5206;&#x91CF;&#xFF1A; &quot; + dataY.length);
            image.close();
        }
    };

    /**
     * &#x76F8;&#x673A;&#x4F1A;&#x8BDD;&#x72B6;&#x6001;&#x63A5;&#x53E3;
     */
    private CameraCaptureSession.StateCallback mSessionStateCallback = new CameraCaptureSession.StateCallback() {

        @Override
        public void onConfigured(CameraCaptureSession session) {
            try {
                //&#x8BBE;&#x7F6E;&#x53CD;&#x590D;&#x6355;&#x83B7;&#x6570;&#x636E;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x8FD9;&#x6837;&#x9884;&#x89C8;&#x754C;&#x9762;&#x5C31;&#x4F1A;&#x4E00;&#x76F4;&#x6709;&#x6570;&#x636E;&#x663E;&#x793A;
                session.setRepeatingRequest(mCaptureRequest.build(), null, mHandler);
            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onConfigureFailed(CameraCaptureSession session) {      }
    };
}
</code></pre>
<h2 id="mediamuxer-&#x5206;&#x79BB;-&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;"><a name="mediamuxer-&#x5206;&#x79BB;-&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;" class="anchor-navigation-ex-anchor" href="#mediamuxer-&#x5206;&#x79BB;-&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. MediaMuxer &#x5206;&#x79BB; &#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;</h2>
<pre><code class="lang-text">private void extractorVideo() throws IOException {
       String inputFilePath = Environment.getExternalStorageDirectory().getPath()+&quot;/input.mp4&quot; ;
       String outputVideoFilePath = Environment.getExternalStorageDirectory().getPath()+&quot;/output.mp4&quot; ;
       MediaMuxer mMediaMuxer =null;
       MediaExtractor mMediaExtractor = new MediaExtractor();
       mMediaExtractor.setDataSource(inputFilePath);

       int mVideoTrackIndex = -1;
       int framerate = 0;
       for (int i = 0; i &lt; mMediaExtractor.getTrackCount(); i++) {
           MediaFormat format = mMediaExtractor.getTrackFormat(i);
           String mime = format.getString(MediaFormat.KEY_MIME);
           if (mime.startsWith(&quot;video/&quot;)) {
               framerate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
               // &#x9009;&#x62E9;&#x89C6;&#x9891;&#x901A;&#x9053;
               mMediaExtractor.selectTrack(i);
               mMediaMuxer = new MediaMuxer(outputVideoFilePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
               mVideoTrackIndex = mMediaMuxer.addTrack(format);
               break;
           }
       }

       MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
       info.presentationTimeUs = 0;
       ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
       int dataSize ;
       mMediaMuxer.start();
       while ( (dataSize = mMediaExtractor.readSampleData(buffer, 0)) &gt; 0) {
           info.offset = 0;
           info.size = dataSize;
           info.flags = MediaCodec.BUFFER_FLAG_SYNC_FRAME;
           info.presentationTimeUs += 1000 * 1000 / framerate;
           mMediaMuxer.writeSampleData(mVideoTrackIndex, buffer, info);
           // &#x7EE7;&#x7EED;&#x8BFB;&#x53D6;&#x4E0B;&#x4E00;&#x5E27;&#x6570;&#x636E;
           mMediaExtractor.advance();
       }
       mMediaExtractor.release();
       mMediaMuxer.stop();
       mMediaMuxer.release();
   }

private void extractorAudio() throws IOException {
      String inputFilePath = Environment.getExternalStorageDirectory().getPath()+&quot;/input.mp4&quot; ;
      String outputVideoFilePath = Environment.getExternalStorageDirectory().getPath()+&quot;/output.mp3&quot; ;
      MediaMuxer mMediaMuxer =null;
      MediaExtractor mMediaExtractor = new MediaExtractor();
      mMediaExtractor.setDataSource(inputFilePath);

      int mVideoTrackIndex = -1;
      int framerate = 0;
      for (int i = 0; i &lt; mMediaExtractor.getTrackCount(); i++) {
          MediaFormat format = mMediaExtractor.getTrackFormat(i);
          String mime = format.getString(MediaFormat.KEY_MIME);
          if (mime.startsWith(&quot;audio/&quot;)) {
              // &#x9009;&#x62E9;&#x89C6;&#x9891;&#x901A;&#x9053;
              mMediaExtractor.selectTrack(i);
              mMediaMuxer = new MediaMuxer(outputVideoFilePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
              mVideoTrackIndex = mMediaMuxer.addTrack(format);
          }else if(mime.startsWith(&quot;video/&quot;)){
              framerate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
          }
      }

      MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
      info.presentationTimeUs = 0;
      ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
      int dataSize ;
      mMediaMuxer.start();
      while ( (dataSize = mMediaExtractor.readSampleData(buffer, 0)) &gt; 0) {
          info.offset = 0;
          info.size = dataSize;
          info.flags = MediaCodec.BUFFER_FLAG_SYNC_FRAME;
          info.presentationTimeUs += 1000 * 1000 / framerate;
          mMediaMuxer.writeSampleData(mVideoTrackIndex, buffer, info);
          // &#x7EE7;&#x7EED;&#x8BFB;&#x53D6;&#x4E0B;&#x4E00;&#x5E27;&#x6570;&#x636E;
          mMediaExtractor.advance();
      }
      mMediaExtractor.release();
      mMediaMuxer.stop();
      mMediaMuxer.release();
  }
</code></pre>
<h2 id="mediamuxer-&#x5C06;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6DF7;&#x5408;"><a name="mediamuxer-&#x5C06;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6DF7;&#x5408;" class="anchor-navigation-ex-anchor" href="#mediamuxer-&#x5C06;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6DF7;&#x5408;"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. MediaMuxer &#x5C06;&#x97F3;&#x9891;&#x3001;&#x89C6;&#x9891;&#x6DF7;&#x5408;</h2>
<pre><code class="lang-text">private void mixVedioAndAudio() {
    String inputVedioPath = Environment.getExternalStorageDirectory().getPath()+&quot;/input.mp4&quot; ;
    String inputAudioPath = Environment.getExternalStorageDirectory().getPath()+&quot;/input.mp3&quot; ;
    String outputVideoFilePath = Environment.getExternalStorageDirectory().getPath()+&quot;/output.mp4&quot; ;

    MediaExtractor videoExtractor ;
    MediaExtractor audioExtractor ;
    MediaMuxer mixMediaMuxer ;

    int framerate = 0;
    try {
        videoExtractor = new MediaExtractor();
        videoExtractor.setDataSource(inputVedioPath);
        int videoIndex = -1;
        MediaFormat videoTrackFormat = null;
        int trackCount = videoExtractor.getTrackCount();
        for (int i = 0; i &lt; trackCount; i++) {
            videoTrackFormat = videoExtractor.getTrackFormat(i);
            if (videoTrackFormat.getString(MediaFormat.KEY_MIME).startsWith(&quot;video/&quot;)) {
                videoIndex = i;
                framerate = videoTrackFormat.getInteger(MediaFormat.KEY_FRAME_RATE);
            }
        }

        audioExtractor = new MediaExtractor();
        audioExtractor.setDataSource(inputAudioPath);
        int audioIndex = -1;
        MediaFormat audioTrackFormat = null;
        trackCount = audioExtractor.getTrackCount();
        for (int i = 0; i &lt; trackCount; i++) {
            audioTrackFormat = audioExtractor.getTrackFormat(i);
            if (audioTrackFormat.getString(MediaFormat.KEY_MIME).startsWith(&quot;audio/&quot;)) {
                audioIndex = i;
            }
        }

        videoExtractor.selectTrack(videoIndex);
        audioExtractor.selectTrack(audioIndex);

        mixMediaMuxer = new MediaMuxer(outputVideoFilePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
        int videoTrackIndex = mixMediaMuxer.addTrack(videoTrackFormat);
        int audioTrackIndex = mixMediaMuxer.addTrack(audioTrackFormat);
        mixMediaMuxer.start();

        ByteBuffer byteBuffer = ByteBuffer.allocate(1024 * 1024);
        MediaCodec.BufferInfo videoBufferInfo = new MediaCodec.BufferInfo();
        MediaCodec.BufferInfo audioBufferInfo = new MediaCodec.BufferInfo();
        while (true) {
            int data = videoExtractor.readSampleData(byteBuffer, 0);
            if (data &lt; 0) {
                break;
            }
            videoBufferInfo.size = data;
            videoBufferInfo.presentationTimeUs +=  1000 *1000 /framerate;
            videoBufferInfo.offset = 0;
            videoBufferInfo.flags = MediaCodec.BUFFER_FLAG_SYNC_FRAME;

            mixMediaMuxer.writeSampleData(videoTrackIndex, byteBuffer, videoBufferInfo);
            videoExtractor.advance();
        }

        while (true) {
            int data = audioExtractor.readSampleData(byteBuffer, 0);
            if (data &lt; 0) {
                break;
            }
            audioBufferInfo.size = data;
            audioBufferInfo.presentationTimeUs +=  1000 *1000 /framerate;
            audioBufferInfo.offset = 0;
            audioBufferInfo.flags = MediaCodec.BUFFER_FLAG_SYNC_FRAME;

            mixMediaMuxer.writeSampleData(audioTrackIndex, byteBuffer, audioBufferInfo);
            audioExtractor.advance();
        }

        mixMediaMuxer.stop();
        mixMediaMuxer.release();
        videoExtractor.release();
        audioExtractor.release();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
</code></pre>
<h2 id="mediacodec-&#x5E38;&#x7528;-api"><a name="mediacodec-&#x5E38;&#x7528;-api" class="anchor-navigation-ex-anchor" href="#mediacodec-&#x5E38;&#x7528;-api"><i class="fa fa-link" aria-hidden="true"></i></a>1.10. MediaCodec &#x5E38;&#x7528; API</h2>
<pre><code class="lang-text">return the output image, or null if  ... or if the codec  was configured with an output surface.
mMeidaCodec.getOutputImage(outputBufferIndex) ;

// &#x6CE8;&#x610F;&#xFF1A; &#x5982;&#x679C;&#x914D;&#x7F6E;&#x4E86; surfaceview&#xFF0C; &#x6570;&#x636E;&#x5C31;&#x88AB;&#x6D88;&#x8017;&#x6389;&#x4E86; &#xFF0C;&#x5C31;&#x62FF;&#x4E0D;&#x5230;&#x89E3;&#x7801;&#x540E;&#x7684;&#x6570;&#x636E;&#x4E86; &#x3002;
mMeidaCodec.configure(mediaFormat, mSurfaceView.getHolder().getSurface(), null, 0);
</code></pre>
<h2 id="mediacodec--camera--surfaceview--&#x9884;&#x89C8;&#x5E76;&#x4FDD;&#x5B58;-h264-&#x6587;&#x4EF6;"><a name="mediacodec--camera--surfaceview--&#x9884;&#x89C8;&#x5E76;&#x4FDD;&#x5B58;-h264-&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#mediacodec--camera--surfaceview--&#x9884;&#x89C8;&#x5E76;&#x4FDD;&#x5B58;-h264-&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.11. MediaCodec + camera + SurfaceView  &#x9884;&#x89C8;&#x5E76;&#x4FDD;&#x5B58; H264 &#x6587;&#x4EF6;</h2>
<p>java&#x5B9E;&#x73B0;</p>
<pre><code class="lang-text">https://gitee.com/hnyer/codeSnippet/tree/master/onlyh264
</code></pre>
<h2 id="camera--surfaceview--audiorecord-mediacodec--mediamuxer-&#x9884;&#x89C8;&#x5E76;&#x751F;&#x6210;-mp4&#x6587;&#x4EF6;"><a name="camera--surfaceview--audiorecord-mediacodec--mediamuxer-&#x9884;&#x89C8;&#x5E76;&#x751F;&#x6210;-mp4&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#camera--surfaceview--audiorecord-mediacodec--mediamuxer-&#x9884;&#x89C8;&#x5E76;&#x751F;&#x6210;-mp4&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.12. camera + SurfaceView + AudioRecord+ MediaCodec+  MediaMuxer &#x9884;&#x89C8;&#x5E76;&#x751F;&#x6210; mp4&#x6587;&#x4EF6;</h2>
<p>java&#x5B9E;&#x73B0;</p>
<pre><code class="lang-text">https://gitee.com/hnyer/codeSnippet/tree/master/muxer
</code></pre>
<h1 id="&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;"><a name="&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;" class="anchor-navigation-ex-anchor" href="#&#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x5E38;&#x7528;ffmpeg&#x4EE3;&#x7801;&#x7247;&#x6BB5;</h1>
<h2 id="&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;"><a name="&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. &#x5BFC;&#x5165;&#x5934;&#x6587;&#x4EF6;</h2>
<pre><code class="lang-text">extern &quot;C&quot;
{
#include &lt;libavcodec/avcodec.h&gt;
}
</code></pre>
<h2 id="&#x904D;&#x5386;-avcodec"><a name="&#x904D;&#x5386;-avcodec" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;-avcodec"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. &#x904D;&#x5386; AVCodec</h2>
<pre><code class="lang-text">av_register_all();
AVCodec * codec= av_codec_next(NULL) ;
while(codec !=NULL)
{
    LOGI(&quot;&#x4FE1;&#x606F; codec-&gt;type =%s&quot; , codec-&gt;name) ;
    // &#x83B7;&#x53D6;&#x4E0B;&#x4E00;&#x4E2A;
    codec = codec-&gt;next ;
}
</code></pre>
<h2 id="&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><a name="&#x914D;&#x7F6E;&#x4FE1;&#x606F;" class="anchor-navigation-ex-anchor" href="#&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.3. &#x914D;&#x7F6E;&#x4FE1;&#x606F;</h2>
<pre><code class="lang-text">const char* configuration  = avcodec_configuration() ;
LOGI(&quot;&#x914D;&#x7F6E;&#x4FE1;&#x606F;configuration =%s&quot; , configuration) ;
</code></pre>
<h2 id="&#x904D;&#x5386;avinputformat"><a name="&#x904D;&#x5386;avinputformat" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;avinputformat"><i class="fa fa-link" aria-hidden="true"></i></a>2.4. &#x904D;&#x5386;AVInputFormat</h2>
<pre><code class="lang-text">av_register_all();
char * info = (char * )malloc(40000);
memset(info,0,40000);
AVInputFormat *if_temp = av_iformat_next(NULL );
while(if_temp!=NULL){
    sprintf(info, &quot;===%s   &quot;, if_temp-&gt;name );
    LOGI(&quot;&#x4FE1;&#x606F; AVInputFormat =%s&quot; , info ) ;
    if_temp=if_temp-&gt;next ;
}
</code></pre>
<h2 id="&#x904D;&#x5386;avoutputformat"><a name="&#x904D;&#x5386;avoutputformat" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;avoutputformat"><i class="fa fa-link" aria-hidden="true"></i></a>2.5. &#x904D;&#x5386;AVOutputFormat</h2>
<pre><code class="lang-text">av_register_all();
char *info=(char * )malloc(40000);
memset(info,0,40000);
AVOutputFormat *of_temp  = av_oformat_next(NULL);
while(of_temp!=NULL){
    sprintf(info, &quot;===%s   &quot;, of_temp-&gt;name);
    LOGI(&quot;&#x4FE1;&#x606F; AVOutputFormat =%s&quot; , info) ;
    of_temp=of_temp-&gt;next;
}
</code></pre>
<h2 id="&#x904D;&#x5386;-avfilter"><a name="&#x904D;&#x5386;-avfilter" class="anchor-navigation-ex-anchor" href="#&#x904D;&#x5386;-avfilter"><i class="fa fa-link" aria-hidden="true"></i></a>2.6. &#x904D;&#x5386; AVFilter</h2>
<pre><code class="lang-text">avfilter_register_all();
char *info=(char * )malloc(40000);
memset(info,0,40000);

AVFilter * f_temp = (AVFilter * )avfilter_next(NULL);
while (f_temp != NULL){
    sprintf(info, &quot;%s&quot;,  f_temp-&gt;name);
    LOGI(&quot;&#x4FE1;&#x606F; AVFilter =%s&quot; , info) ;
    f_temp=f_temp-&gt;next;
}
</code></pre>
<h2 id="mp3-&#x8F6C;-aac"><a name="mp3-&#x8F6C;-aac" class="anchor-navigation-ex-anchor" href="#mp3-&#x8F6C;-aac"><i class="fa fa-link" aria-hidden="true"></i></a>2.7. mp3 &#x8F6C; aac</h2>
<pre><code class="lang-text">// &#x8F6C;&#x6362;&#x547D;&#x4EE4;
ffmpeg -i xxx.mp3  xxx.aac

JNIEXPORT jint xxxxxxxxxxxMp3ToAAC
(JNIEnv * env, jclass obj, jobjectArray commands)
{
    int argc = ( * env)-&gt;GetArrayLength(env, commands);
    char **argv = (char * * )malloc(argc * sizeof(char* ));
    int i;
    int result;
    for (i = 0; i &lt; argc; i++)
    {
        jstring jstr = (jstring) (* env)-&gt;GetObjectArrayElement(env, commands, i);
        char* temp = (char* ) (* env)-&gt;GetStringUTFChars(env, jstr, 0);
        argv[i] = malloc(1024);
        strcpy(argv[i], temp);
        (*env)-&gt;ReleaseStringUTFChars(env, jstr, temp);
    }
    //&#x6267;&#x884C;ffmpeg&#x547D;&#x4EE4; ,  &#x5C06;&#x6E90;&#x7801;&#x4E2D;&#x7684; main() &#x6539;&#x6210;run()
    result =  run(argc, argv);
    //&#x91CA;&#x653E;&#x5185;&#x5B58;
    for (i = 0; i &lt; argc; i++)
    {
        free(argv[i]);
    }
    free(argv);
    return result;
}
</code></pre>
<h2 id="&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;"><a name="&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;" class="anchor-navigation-ex-anchor" href="#&#x97F3;&#x9891;&#x89E3;&#x7801;--&#x64AD;&#x653E;"><i class="fa fa-link" aria-hidden="true"></i></a>2.8. &#x97F3;&#x9891;&#x89E3;&#x7801; + &#x64AD;&#x653E;</h2>
<p>native ffmpeg &#x5B9E;&#x73B0;&#x89E3;&#x7801; &#xFF0C; java&#x5C42;&#x7684; AudioTrack &#x5B9E;&#x73B0;&#x64AD;&#x653E;</p>
<pre><code class="lang-text">#define MAX_AUDIO_FRAME_SIZE 48000 * 4
JNIEXPORT void JNICALL Java_xxxx_play
  (JNIEnv *env, jobject jthiz, jstring input_jstr){
    const char* input_cstr = (*env)-&gt;GetStringUTFChars(env,input_jstr,NULL);
    //&#x6CE8;&#x518C;&#x7EC4;&#x4EF6;
    av_register_all();
    AVFormatContext *pFormatCtx = avformat_alloc_context();
    //&#x6253;&#x5F00;&#x97F3;&#x9891;&#x6587;&#x4EF6;
    if(avformat_open_input(&amp;pFormatCtx,input_cstr,NULL,NULL) != 0)
    {
        return;
    }
    //&#x83B7;&#x53D6;&#x8F93;&#x5165;&#x6587;&#x4EF6;&#x4FE1;&#x606F;
    if(avformat_find_stream_info(pFormatCtx,NULL) &lt; 0){
        return;
    }
    //&#x83B7;&#x53D6;&#x97F3;&#x9891;&#x6D41;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;
    int  audio_stream_idx = -1;
    for(int i=0; i &lt; pFormatCtx-&gt;nb_streams;i++)
    {
        if(pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_AUDIO)
        {
            audio_stream_idx = i;
            break;
        }
    }

    //&#x83B7;&#x53D6;&#x97F3;&#x9891;&#x89E3;&#x7801;&#x5668;
    AVCodecContext *codecCtx = pFormatCtx-&gt;streams[audio_stream_idx]-&gt;codec;
    AVCodec *codec = avcodec_find_decoder(codecCtx-&gt;codec_id);
    if(codec == NULL)
    {
        return;
    }
    //&#x6253;&#x5F00;&#x89E3;&#x7801;&#x5668;
    if(avcodec_open2(codecCtx,codec,NULL) &lt; 0)
    {
        return;
    }
    //&#x89E3;&#x7801;&#x4E4B;&#x524D;&#x7684;&#x6570;&#x636E;
    AVPacket *packet = (AVPacket *)av_malloc(sizeof(AVPacket));
    //&#x89E3;&#x7801;&#x4E4B;&#x540E;&#x7684;&#x6570;&#x636E;
    AVFrame *frame = av_frame_alloc();

    //&#x8F93;&#x5165;&#x7684;&#x91C7;&#x6837;&#x683C;&#x5F0F;
    enum AVSampleFormat in_sample_fmt = codecCtx-&gt;sample_fmt;
    //&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x683C;&#x5F0F;16bit PCM
    enum AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_S16;
    //&#x8F93;&#x5165;&#x91C7;&#x6837;&#x7387;
    int in_sample_rate = codecCtx-&gt;sample_rate;
    //&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x7387;
    int out_sample_rate = in_sample_rate;
    //&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;2&#x4E2A;&#x58F0;&#x9053;&#xFF0C;&#x9ED8;&#x8BA4;&#x7ACB;&#x4F53;&#x58F0;stereo&#xFF09;
    uint64_t in_ch_layout = codecCtx-&gt;channel_layout;
    //&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;&#x7ACB;&#x4F53;&#x58F0;&#xFF09;
    uint64_t out_ch_layout = AV_CH_LAYOUT_STEREO;
    //&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x4E2A;&#x6570;
    int out_channel_nb = av_get_channel_layout_nb_channels(out_ch_layout);
    //&#x97F3;&#x9891;&#x91CD;&#x91C7;&#x6837;
    SwrContext *swrCtx = swr_alloc();
    swr_alloc_set_opts(swrCtx,
          out_ch_layout,out_sample_fmt,out_sample_rate,
          in_ch_layout,in_sample_fmt,in_sample_rate,
          0, NULL);
    swr_init(swrCtx);

    // &#x83B7;&#x53D6;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;c&#x6587;&#x4EF6;&#x7684;java&#x6587;&#x4EF6;&#x7C7B;
    jclass player_class = (*env)-&gt;GetObjectClass(env,jthiz);
    if(!player_class){
        return;
    }
    //&#x627E;&#x5230; java&#x4EE3;&#x7801;&#x4E2D;&#x7684;  public AudioTrack createAudioTrack(int sampleRate, int channels) &#x65B9;&#x6CD5;
    jmethodID audio_track_method = (*env)-&gt;GetMethodID(env,player_class,&quot;createAudioTrack&quot;,&quot;(II)Landroid/media/AudioTrack;&quot;);
    if(!audio_track_method){
        return;
    }
    // &#x4F7F;&#x7528;java&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x65B9;&#x6CD5;
    jobject audio_track = (*env)-&gt;CallObjectMethod(env,jthiz,audio_track_method,out_sample_rate,out_channel_nb);

    //&#x8C03;&#x7528;AudioTrack &#x7684; play() &#x65B9;&#x6CD5;
    jclass audio_track_class = (*env)-&gt;GetObjectClass(env,audio_track);
    jmethodID audio_track_play_mid = (*env)-&gt;GetMethodID(env,audio_track_class,&quot;play&quot;,&quot;()V&quot;);
    (*env)-&gt;CallVoidMethod(env,audio_track,audio_track_play_mid);

    //&#x8F6C;&#x6362;&#x683C;&#x5F0F;&#x540E;&#x7684;&#x6570;&#x636E;
    uint8_t *out_buffer = (uint8_t *)av_malloc(MAX_AUDIO_FRAME_SIZE);

    int got_frame = 0 ;
    //&#x4E0D;&#x65AD;&#x8BFB;&#x53D6;&#x7F16;&#x7801;&#x6570;&#x636E;
    while (av_read_frame(pFormatCtx, packet) &gt;= 0)
    {
        if (packet-&gt;stream_index == audio_stream_idx)
        {
            //&#x97F3;&#x9891;&#x89E3;&#x7801;
            int ret = avcodec_decode_audio4(codecCtx, frame, &amp;got_frame, packet);
            if (ret &lt; 0)
            {
                break;
            }
            //&#x89E3;&#x7801;&#x4E00;&#x5E27;&#x6210;&#x529F;
            if (got_frame &gt; 0)
            {
                //&#x97F3;&#x9891;&#x683C;&#x5F0F;&#x8F6C;&#x6362;
                swr_convert(swrCtx, &amp;out_buffer, MAX_AUDIO_FRAME_SIZE, (const uint8_t **) frame-&gt;data, frame-&gt;nb_samples);
                int out_buffer_size = av_samples_get_buffer_size(NULL,
                                                                 out_channel_nb,
                                                                 frame-&gt;nb_samples,
                                                                 out_sample_fmt,
                                                                 1);

                jbyteArray audio_sample_array = (*env)-&gt;NewByteArray(env, out_buffer_size);
                jbyte *sample_byte_array = (*env)-&gt;GetByteArrayElements(env, audio_sample_array,
                                                                        NULL);
                //&#x62F7;&#x8D1D;&#x7F13;&#x51B2;&#x6570;&#x636E;
                memcpy(sample_byte_array, out_buffer, (size_t) out_buffer_size);
                //&#x91CA;&#x653E;&#x6570;&#x7EC4;
                (*env)-&gt;ReleaseByteArrayElements(env, audio_sample_array, sample_byte_array, 0);

                //&#x8C03;&#x7528;AudioTrack &#x7684; &#x83B7;&#x53D6;write(...)&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x64AD;&#x653E;
                jmethodID audio_track_write_mid = (*env)-&gt;GetMethodID(env, audio_track_class,
                                                                      &quot;write&quot;, &quot;([BII)I&quot;);
                (*env)-&gt;CallIntMethod(env,
                                      audio_track,
                                      audio_track_write_mid,
                                      audio_sample_array,
                                      0,
                                      out_buffer_size);
                //&#x91CA;&#x653E;&#x5C40;&#x90E8;&#x5F15;&#x7528;
                (*env)-&gt;DeleteLocalRef(env, audio_sample_array);
                usleep(1000 * 16);
            }
        }
        av_free_packet(packet);
    }

    av_frame_free(&amp;frame);
    av_free(out_buffer);
    swr_free(&amp;swrCtx);
    avcodec_close(codecCtx);
    avformat_close_input(&amp;pFormatCtx);
    (*env)-&gt;ReleaseStringUTFChars(env,input_jstr,input_cstr);
}


public AudioTrack createAudioTrack(int sampleRate, int channels){
    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    int channelConfig;
    if(channels == 1){
        // &#x5355;&#x58F0;&#x9053;
        channelConfig = AudioFormat.CHANNEL_OUT_MONO;
    }else if(channels == 2){
        // &#x8F93;&#x51FA;&#x58F0;&#x9053;&#x4E3A;&#x53CC;&#x58F0;&#x9053;&#x7ACB;&#x4F53;&#x58F0;
        channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
    }else{
        channelConfig = AudioFormat.CHANNEL_OUT_STEREO;
    }
    // sampleRate  &#x91C7;&#x6837;&#x7387;
    int bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);
    return new AudioTrack(AudioManager.STREAM_MUSIC,
            sampleRate, channelConfig, audioFormat,bufferSizeInBytes, AudioTrack.MODE_STREAM);
}
</code></pre>
<h2 id="native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;"><a name="native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;" class="anchor-navigation-ex-anchor" href="#native-ffmpeg-&#x5B9E;&#x73B0;&#x89E3;&#x7801;-&#xFF0C;-native-&#x5C42;&#x7684;-opensl-&#x5B9E;&#x73B0;&#x64AD;&#x653E;"><i class="fa fa-link" aria-hidden="true"></i></a>2.9. native ffmpeg &#x5B9E;&#x73B0;&#x89E3;&#x7801; &#xFF0C; native &#x5C42;&#x7684; opensl &#x5B9E;&#x73B0;&#x64AD;&#x653E;</h2>
<pre><code class="lang-text">//OpenSLES - &#x5BF9;&#x8C61;&#x63A5;&#x53E3;-
SLObjectItf engineObject = NULL;
// OpenSLES - &#x5F15;&#x64CE;&#x63A5;&#x53E3;-
SLEngineItf engineEngine;
//&#x8F93;&#x51FA;&#x6DF7;&#x97F3;&#x5668;&#x63A5;&#x53E3;
SLObjectItf outputMixObject = NULL;
// &#x6DF7;&#x97F3;&#x5668;&#x73AF;&#x5883;&#x63A5;&#x53E3;
SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;
//&#x7F13;&#x51B2;&#x64AD;&#x653E;&#x5668;&#x63A5;&#x53E3;
SLObjectItf bqPlayerObject = NULL;
// &#x64AD;&#x653E;&#x63A5;&#x53E3;
SLPlayItf bqPlayerPlay;
SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
SLEffectSendItf bqPlayerEffectSend;
SLVolumeItf bqPlayerVolume;
//&#x97F3;&#x6548;&#x8BBE;&#x7F6E;
const SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
void *buffer;
size_t bufferSize;
uint8_t *outputBuffer;
// &#x5206;&#x914D;PCM&#x6570;&#x636E;&#x7F13;&#x5B58;
size_t outputBufferSize;

//FFmpeg&#x76F8;&#x5173;
AVPacket packet;
//&#x97F3;&#x9891;&#x6D41;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;
int audioStream;
AVFrame *aFrame;
SwrContext *swr;
AVFormatContext *aFormatCtx;
AVCodecContext *aCodecCtx;
int frame_count = 0;
int createAudioPlayer(int *rate, int *channel, const char *file_name) ;
int releaseAudioPlayer();
int getPCM(void **pcm, size_t *pcmSize) ;

//&#x64AD;&#x653E;&#x56DE;&#x8C03;&#x65B9;&#x6CD5;
void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bufferQueueItf, void *context)
{
    bufferSize = 0;
    getPCM(&amp;buffer, &amp;bufferSize);
    //&#x5982;&#x679C;buffer&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;&#x5165;&#x5F85;&#x64AD;&#x653E;&#x961F;&#x5217;
    if (NULL != buffer &amp;&amp; 0 != bufferSize) {
        SLresult result;
        result = (*bqPlayerBufferQueue)-&gt;Enqueue(bqPlayerBufferQueue, buffer, bufferSize);
        if(result &lt; 0){
            LOGE(&quot;Enqueue error...&quot;);
        } else{
            LOGI(&quot;decode frame count=%d&quot;, frame_count++);
        }
    }
}

void createEngine()
{
    // &#x64CD;&#x4F5C;&#x7ED3;&#x679C;
    SLresult result;
    //&#x521B;&#x5EFA;&#x5F15;&#x64CE;
    result = slCreateEngine(&amp;engineObject, 0, NULL, 0, NULL, NULL);
    result = (*engineObject)-&gt;Realize(engineObject, SL_BOOLEAN_FALSE);
    //&#x83B7;&#x53D6;&#x5F15;&#x64CE;&#x63A5;&#x53E3;
    result = (*engineObject)-&gt;GetInterface(engineObject, SL_IID_ENGINE, &amp;engineEngine);
    //&#x521B;&#x5EFA;&#x8F93;&#x51FA;&#x6DF7;&#x97F3;&#x5668;
    result = (*engineEngine)-&gt;CreateOutputMix(engineEngine, &amp;outputMixObject, 0, 0, 0);
    //&#x5173;&#x8054;&#x8F93;&#x51FA;&#x6DF7;&#x97F3;&#x5668;
    result = (*outputMixObject)-&gt;Realize(outputMixObject, SL_BOOLEAN_FALSE);
    //&#x83B7;&#x53D6;reverb&#x63A5;&#x53E3;
    result = (*outputMixObject)-&gt;GetInterface(outputMixObject,
                                              SL_IID_ENVIRONMENTALREVERB,
                                              &amp;outputMixEnvironmentalReverb);
    if (SL_RESULT_SUCCESS == result)
    {
        result = (*outputMixEnvironmentalReverb)-&gt;SetEnvironmentalReverbProperties(
                outputMixEnvironmentalReverb, &amp;reverbSettings);
    }
}

void createBufferQueueAudioPlayer(int rate, int channel, int bitsPerSample)
{
    SLresult result;
    //&#x914D;&#x7F6E;&#x97F3;&#x9891;&#x6E90;
    SLDataLocator_AndroidSimpleBufferQueue buffer_queue = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
    SLDataFormat_PCM format_pcm;
    format_pcm.formatType = SL_DATAFORMAT_PCM;
    format_pcm.numChannels = (SLuint32) channel;
    format_pcm.bitsPerSample = (SLuint32) bitsPerSample;
    format_pcm.samplesPerSec = (SLuint32) (rate * 1000);
    format_pcm.containerSize = 16;
    if (channel == 2)
    {
        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
    } else{
        format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
    }
    format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
    SLDataSource audioSrc = {&amp;buffer_queue, &amp;format_pcm};
    //&#x914D;&#x7F6E;&#x97F3;&#x9891;&#x6C60;
    SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
    SLDataSink audioSnk = {&amp;loc_outmix, NULL};
    //&#x521B;&#x5EFA;&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;
    const SLInterfaceID ids[3] = {SL_IID_BUFFERQUEUE, SL_IID_EFFECTSEND, SL_IID_VOLUME};
    const SLboolean req[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE};
    result = (*engineEngine)-&gt;CreateAudioPlayer(engineEngine,
                                                &amp;bqPlayerObject,
                                                &amp;audioSrc,
                                                &amp;audioSnk,
                                                3,
                                                ids,
                                                req);
    //&#x5173;&#x8054;&#x64AD;&#x653E;&#x5668;
    result = (*bqPlayerObject)-&gt;Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
    //&#x83B7;&#x53D6;&#x64AD;&#x653E;&#x63A5;&#x53E3;
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_PLAY, &amp;bqPlayerPlay);
    //&#x83B7;&#x53D6;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x63A5;&#x53E3;
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_BUFFERQUEUE,
                                             &amp;bqPlayerBufferQueue);
    //&#x6CE8;&#x518C;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x56DE;&#x8C03;
    result = (*bqPlayerBufferQueue)-&gt;RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL);
    //&#x83B7;&#x53D6;&#x97F3;&#x6548;&#x63A5;&#x53E3;
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_EFFECTSEND,
                                             &amp;bqPlayerEffectSend);
    //&#x83B7;&#x53D6;&#x97F3;&#x91CF;&#x63A5;&#x53E3;
    result = (*bqPlayerObject)-&gt;GetInterface(bqPlayerObject, SL_IID_VOLUME, &amp;bqPlayerVolume);
    //&#x5F00;&#x59CB;&#x64AD;&#x653E;&#x97F3;&#x4E50;
    result = (*bqPlayerPlay)-&gt;SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
}

int createAudioPlayer(int *rate, int *channel, const char *file_name)
{
    av_register_all();
    aFormatCtx = avformat_alloc_context();

    if (avformat_open_input(&amp;aFormatCtx, file_name, NULL, NULL) != 0)
    {
        return -1;
    }

    if (avformat_find_stream_info(aFormatCtx, NULL) &lt; 0) {
        return -1;
    }

    for (int i = 0; i &lt; aFormatCtx-&gt;nb_streams; i++)
    {
        if (aFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_AUDIO &amp;&amp; audioStream &lt; 0) {
            audioStream = i;
        }
    }
    if (audioStream == -1)
    {
        return -1;
    }
    aCodecCtx = aFormatCtx-&gt;streams[audioStream]-&gt;codec;
    AVCodec *aCodec = avcodec_find_decoder(aCodecCtx-&gt;codec_id);
    if (aCodec==NULL)
    {
        return -1;
    }
    if (avcodec_open2(aCodecCtx, aCodec, NULL) &lt; 0)
    {
        return -1;
    }
    aFrame = av_frame_alloc();

    // &#x8BBE;&#x7F6E;&#x683C;&#x5F0F;&#x8F6C;&#x6362; ,  &#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;swr_alloc_set_opts(...)&#x8BBE;&#x7F6E;
    swr = swr_alloc();
    av_opt_set_int(swr, &quot;in_channel_layout&quot;,  aCodecCtx-&gt;channel_layout, 0);
    av_opt_set_int(swr, &quot;out_channel_layout&quot;, aCodecCtx-&gt;channel_layout,  0);
    av_opt_set_int(swr, &quot;in_sample_rate&quot;,     aCodecCtx-&gt;sample_rate, 0);
    av_opt_set_int(swr, &quot;out_sample_rate&quot;,    aCodecCtx-&gt;sample_rate, 0);
    av_opt_set_sample_fmt(swr, &quot;in_sample_fmt&quot;,  aCodecCtx-&gt;sample_fmt, 0);
    av_opt_set_sample_fmt(swr, &quot;out_sample_fmt&quot;, AV_SAMPLE_FMT_S16,  0);
    swr_init(swr);

    outputBufferSize = 8196;
    outputBuffer = (uint8_t *) malloc(sizeof(uint8_t) * outputBufferSize);
    // &#x8FD4;&#x56DE;sample rate&#x548C;channels
    *rate = aCodecCtx-&gt;sample_rate;
    *channel = aCodecCtx-&gt;channels;
    return 0;
}

// &#x83B7;&#x53D6;PCM&#x6570;&#x636E;, &#x81EA;&#x52A8;&#x56DE;&#x8C03;&#x83B7;&#x53D6;
int getPCM(void **pcm, size_t *pcmSize)
{
    while (av_read_frame(aFormatCtx, &amp;packet) &gt;= 0)
    {
        int frameFinished = 0;
        //&#x97F3;&#x9891;&#x6D41;
        if (packet.stream_index == audioStream)
        {
            avcodec_decode_audio4(aCodecCtx, aFrame, &amp;frameFinished, &amp;packet);
            //&#x89E3;&#x7801;&#x5B8C;&#x4E00;&#x5E27;&#x6570;&#x636E;
            if (frameFinished)
            {
                // data_size&#x4E3A;&#x97F3;&#x9891;&#x6570;&#x636E;&#x6240;&#x5360;&#x7684;&#x5B57;&#x8282;&#x6570;
                int data_size = av_samples_get_buffer_size(
                        aFrame-&gt;linesize, aCodecCtx-&gt;channels,
                        aFrame-&gt;nb_samples, aCodecCtx-&gt;sample_fmt, 1);

                if (data_size &gt; outputBufferSize)
                {
                    outputBufferSize = (size_t) data_size;
                    outputBuffer = (uint8_t *) realloc(outputBuffer, sizeof(uint8_t) * outputBufferSize);
                }

                // &#x97F3;&#x9891;&#x683C;&#x5F0F;&#x8F6C;&#x6362;
                swr_convert(swr, &amp;outputBuffer, aFrame-&gt;nb_samples,
                            (uint8_t const **) (aFrame-&gt;extended_data),
                            aFrame-&gt;nb_samples);

                // &#x8FD4;&#x56DE;pcm&#x6570;&#x636E;
                *pcm = outputBuffer;
                *pcmSize = (size_t) data_size;
                return 0;
            }
        }
    }
    return -1;
}

// &#x91CA;&#x653E;&#x76F8;&#x5173;&#x8D44;&#x6E90;
int releaseAudioPlayer()
{
    av_packet_unref(&amp;packet);
    av_free(outputBuffer);
    av_free(aFrame);
    avcodec_close(aCodecCtx);
    avformat_close_input(&amp;aFormatCtx);
    return 0;
}

// &#x5BF9;&#x5916;&#x64AD;&#x653E;&#x63A5;&#x53E3; &#xFF0C;&#x4F20;&#x5165; mp3 &#x7EDD;&#x5BF9;&#x5730;&#x5740;
JNIEXPORT void JNICALL Java_com_frank_ffmpeg_AudioPlayer_playAudio
        (JNIEnv * env, jclass jobject, jstring filePath)
{
    int rate, channel;
    const char *file_name = (*env)-&gt;GetStringUTFChars(env, filePath, NULL);
    // &#x521B;&#x5EFA;&#x97F3;&#x9891;&#x89E3;&#x7801;&#x5668;
    createAudioPlayer(&amp;rate, &amp;channel, file_name);
    // &#x521B;&#x5EFA;OpenSLES&#x5F15;&#x64CE;
    createEngine();
    // &#x521B;&#x5EFA;&#x5E26;&#x6709;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x7684;&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;
    createBufferQueueAudioPlayer(rate, channel, SL_PCMSAMPLEFORMAT_FIXED_16);
    // &#x542F;&#x52A8;&#x97F3;&#x9891;&#x64AD;&#x653E;
    bqPlayerCallback(bqPlayerBufferQueue, NULL);
}

//&#x505C;&#x6B62;&#x64AD;&#x653E;&#xFF0C;&#x91CA;&#x653E;&#x76F8;&#x5173;&#x8D44;&#x6E90;
JNIEXPORT jint JNICALL Java_com_frank_ffmpeg_AudioPlayer_stop
        (JNIEnv * env, jclass jobject) {
    if (bqPlayerObject != NULL) {
        (*bqPlayerObject)-&gt;Destroy(bqPlayerObject);
        bqPlayerObject = NULL;
        bqPlayerPlay = NULL;
        bqPlayerBufferQueue = NULL;
        bqPlayerEffectSend = NULL;
        bqPlayerVolume = NULL;
    }

    if (outputMixObject != NULL) {
        (*outputMixObject)-&gt;Destroy(outputMixObject);
        outputMixObject = NULL;
        outputMixEnvironmentalReverb = NULL;
    }

    if (engineObject != NULL) {
        (*engineObject)-&gt;Destroy(engineObject);
        engineObject = NULL;
        engineEngine = NULL;
    }

    // &#x91CA;&#x653E;&#x89E3;&#x7801;&#x5668;&#x76F8;&#x5173;&#x8D44;&#x6E90;
    releaseAudioPlayer();
}
</code></pre>
<h2 id="&#x64AD;&#x653E;&#x672C;&#x5730;mp4"><a name="&#x64AD;&#x653E;&#x672C;&#x5730;mp4" class="anchor-navigation-ex-anchor" href="#&#x64AD;&#x653E;&#x672C;&#x5730;mp4"><i class="fa fa-link" aria-hidden="true"></i></a>2.10. &#x64AD;&#x653E;&#x672C;&#x5730;MP4</h2>
<pre><code class="lang-text">#define MAX_AUDIO_FRAME_SIZE 48000 * 4
#define PACKET_SIZE 50
#define MIN_SLEEP_TIME_US 1000ll
#define AUDIO_TIME_ADJUST_US -200000ll

typedef struct MediaPlayer{
    AVFormatContext* format_context;
    int video_stream_index;
    int audio_stream_index;
    AVCodecContext* video_codec_context;
    AVCodecContext* audio_codec_context;
    AVCodec* video_codec;
    AVCodec* audio_codec;
    ANativeWindow* native_window;
    uint8_t* buffer;
    AVFrame* yuv_frame;
    AVFrame* rgba_frame;
    int video_width;
    int video_height;
    SwrContext* swrContext;
    int out_channel_nb;
    int out_sample_rate;
    enum AVSampleFormat out_sample_fmt;
    jobject audio_track;
    jmethodID audio_track_write_mid;
    uint8_t* audio_buffer;
    AVFrame* audio_frame;
    AVPacketQueue* packets[2];
    pthread_mutex_t mutex;
    pthread_cond_t cond;
    int64_t start_time;
    int64_t audio_clock;
    pthread_t write_thread;
    pthread_t video_thread;
    pthread_t audio_thread;
}MediaPlayer;

typedef struct Decoder{
    MediaPlayer* player;
    int stream_index;
}Decoder;

JavaVM* javaVM;
MediaPlayer* player;


jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
    javaVM = vm;
    return JNI_VERSION_1_6;
}

int init_input_format_context(MediaPlayer* player, const char* file_name)
{
    av_register_all();
    player-&gt;format_context = avformat_alloc_context();
    if(avformat_open_input(&amp;player-&gt;format_context, file_name, NULL, NULL)!=0)
    {
        return -1;
    }
    //&#x67E5;&#x627E;&#x662F;&#x5426;&#x6709;&#x97F3;&#x9891; &#x6216; &#x89C6;&#x9891;&#x4FE1;&#x606F;
    if(avformat_find_stream_info(player-&gt;format_context, NULL)&lt;0)
    {
        return -1;
    }
    //&#x5BFB;&#x627E;&#x97F3;&#x89C6;&#x9891;&#x6D41;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;
    player-&gt;video_stream_index = -1;
    player-&gt;audio_stream_index = -1;
    for (int i = 0; i &lt; player-&gt;format_context-&gt;nb_streams; i++)
    {
        if (player-&gt;format_context-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO &amp;&amp; player-&gt;video_stream_index &lt; 0)
        {
            player-&gt;video_stream_index = i;
        } else if (player-&gt;format_context-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_AUDIO &amp;&amp; player-&gt;audio_stream_index &lt; 0) {
            player-&gt;audio_stream_index = i;
        }
    }
    if(player-&gt;video_stream_index==-1)
    {
        // &#x6CA1;&#x6709;&#x89C6;&#x9891;&#x4FE1;&#x606F;
        return -1;
    }
    if(player-&gt;audio_stream_index==-1)
    {
       // &#x6CA1;&#x6709;&#x97F3;&#x9891;&#x4FE1;&#x606F;
        return -1;
    }
    return 0;
}

//&#x6253;&#x5F00;&#x97F3;&#x89C6;&#x9891;&#x89E3;&#x7801;&#x5668;
int init_condec_context(MediaPlayer* player)
{
    //&#x83B7;&#x53D6;codec&#x4E0A;&#x4E0B;&#x6587;&#x6307;&#x9488;
    player-&gt;video_codec_context = player-&gt;format_context-&gt;streams[player-&gt;video_stream_index]-&gt;codec;
    //&#x5BFB;&#x627E;&#x89C6;&#x9891;&#x6D41;&#x7684;&#x89E3;&#x7801;&#x5668;
    player-&gt;video_codec = avcodec_find_decoder(player-&gt;video_codec_context-&gt;codec_id);
    if(player-&gt;video_codec == NULL)
    {
        return -1;
    }
    // &#x6253;&#x5F00;&#x89E3;&#x7801;&#x5668;
    if(avcodec_open2(player-&gt;video_codec_context, player-&gt;video_codec, NULL) &lt; 0)
    {
        return -1;
    }
    player-&gt;audio_codec_context = player-&gt;format_context-&gt;streams[player-&gt;audio_stream_index]-&gt;codec;
    player-&gt;audio_codec = avcodec_find_decoder(player-&gt;audio_codec_context-&gt;codec_id);
    if( player-&gt;audio_codec == NULL)
    {
        return -1;
    }
    if(avcodec_open2(player-&gt;audio_codec_context, player-&gt;audio_codec, NULL) &lt; 0)
    {
        return -1;
    }
    // &#x83B7;&#x53D6;&#x89C6;&#x9891;&#x5BBD;&#x9AD8;
    player-&gt;video_width = player-&gt;video_codec_context-&gt;width;
    player-&gt;video_height = player-&gt;video_codec_context-&gt;height;
    return 0;
}

// &#x83B7;&#x5F97; ANativeWindow  surface
void video_player_prepare(MediaPlayer* player, JNIEnv* env, jobject surface)
{
    player-&gt;native_window = ANativeWindow_fromSurface(env, surface);
}

//&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x64AD;&#x653E;&#x65F6;&#x95F4;
int64_t get_play_time(MediaPlayer* player){
    return (int64_t)(av_gettime() - player-&gt;start_time);
}

// &#x97F3;&#x89C6;&#x9891;&#x540C;&#x6B65;
void player_wait_for_frame(MediaPlayer *player, int64_t stream_time)
{
    pthread_mutex_lock(&amp;player-&gt;mutex);
    for(;;){
        int64_t current_video_time = get_play_time(player);
        int64_t sleep_time = stream_time - current_video_time;
        if (sleep_time &lt; -300000ll) {
            // 300 ms late
            int64_t new_value = player-&gt;start_time - sleep_time;
            player-&gt;start_time = new_value;
            pthread_cond_broadcast(&amp;player-&gt;cond);
        }

        if (sleep_time &lt;= MIN_SLEEP_TIME_US) {
            // We do not need to wait if time is slower then minimal sleep time
            break;
        }

        if (sleep_time &gt; 500000ll) {
            // if sleep time is bigger then 500ms just sleep this 500ms
            // and check everything again
            sleep_time = 500000ll;
        }
        //&#x7B49;&#x5F85;&#x6307;&#x5B9A;&#x65F6;&#x957F;
        pthread_cond_timeout_np(&amp;player-&gt;cond, &amp;player-&gt;mutex,
                                                  (unsigned int) (sleep_time / 1000ll));
    }
    pthread_mutex_unlock(&amp;player-&gt;mutex);
}

//&#x89C6;&#x9891;&#x89E3;&#x7801;
int decode_video(MediaPlayer* player, AVPacket* packet)
{
    ANativeWindow_setBuffersGeometry(player-&gt;native_window,  player-&gt;video_width,
                                     player-&gt;video_height, WINDOW_FORMAT_RGBA_8888);

    ANativeWindow_Buffer windowBuffer;
    player-&gt;yuv_frame = av_frame_alloc();
    player-&gt;rgba_frame = av_frame_alloc();
    if(player-&gt;rgba_frame == NULL || player-&gt;yuv_frame == NULL)
    {
        return -1;
    }

    // buffer&#x4E2D;&#x6570;&#x636E;&#x7528;&#x4E8E;&#x6E32;&#x67D3;,&#x4E14;&#x683C;&#x5F0F;&#x4E3A;RGBA
    int numBytes=av_image_get_buffer_size(AV_PIX_FMT_RGBA, player-&gt;video_width, player-&gt;video_height, 1);

    player-&gt;buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
    av_image_fill_arrays(player-&gt;rgba_frame-&gt;data,
                         player-&gt;rgba_frame-&gt;linesize,
                         player-&gt;buffer,
                         AV_PIX_FMT_RGBA,
                         player-&gt;video_width,
                         player-&gt;video_height,
                         1);

    // &#x7531;&#x4E8E;&#x89E3;&#x7801;&#x51FA;&#x6765;&#x7684;&#x5E27;&#x683C;&#x5F0F;&#x4E0D;&#x662F;RGBA&#x7684;,&#x5728;&#x6E32;&#x67D3;&#x4E4B;&#x524D;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x683C;&#x5F0F;&#x8F6C;&#x6362;
    struct SwsContext *sws_ctx = sws_getContext(
            player-&gt;video_width,
            player-&gt;video_height,
            player-&gt;video_codec_context-&gt;pix_fmt,
            player-&gt;video_width,
            player-&gt;video_height,
            AV_PIX_FMT_RGBA,
            SWS_BILINEAR,
            NULL,
            NULL,
            NULL);

    int frameFinished;
    //&#x89E3;&#x7801;
    int ret = avcodec_decode_video2(player-&gt;video_codec_context, player-&gt;yuv_frame, &amp;frameFinished, packet);
    if(ret &lt; 0)
    {
        return -1;
    }
    if (frameFinished) {
        // lock native window
        ANativeWindow_lock(player-&gt;native_window, &amp;windowBuffer, 0);
        // &#x683C;&#x5F0F;&#x8F6C;&#x6362;
        sws_scale(sws_ctx, (uint8_t const * const *)player-&gt;yuv_frame-&gt;data,
                  player-&gt;yuv_frame-&gt;linesize, 0, player-&gt;video_height,
                  player-&gt;rgba_frame-&gt;data, player-&gt;rgba_frame-&gt;linesize);
        // &#x83B7;&#x53D6;stride
        uint8_t * dst = windowBuffer.bits;
        int dstStride = windowBuffer.stride * 4;
        uint8_t * src = player-&gt;rgba_frame-&gt;data[0];
        int srcStride = player-&gt;rgba_frame-&gt;linesize[0];
        // &#x7531;&#x4E8E;window&#x7684;stride&#x548C;&#x5E27;&#x7684;stride&#x4E0D;&#x540C;,&#x56E0;&#x6B64;&#x9700;&#x8981;&#x9010;&#x884C;&#x590D;&#x5236;
        int h;
        for (h = 0; h &lt; player-&gt;video_height; h++)
        {
            memcpy(dst + h * dstStride, src + h * srcStride, (size_t) srcStride);
        }

        //&#x8BA1;&#x7B97;&#x5EF6;&#x8FDF;
        int64_t pts = av_frame_get_best_effort_timestamp(player-&gt;yuv_frame);
        AVStream *stream = player-&gt;format_context-&gt;streams[player-&gt;video_stream_index];
        //&#x8F6C;&#x6362;&#xFF08;&#x4E0D;&#x540C;&#x65F6;&#x95F4;&#x57FA;&#x65F6;&#x95F4;&#x8F6C;&#x6362;&#xFF09;
        int64_t time = av_rescale_q(pts, stream-&gt;time_base, AV_TIME_BASE_Q);
        //&#x97F3;&#x89C6;&#x9891;&#x5E27;&#x540C;&#x6B65;
        player_wait_for_frame(player, time);
        ANativeWindow_unlockAndPost(player-&gt;native_window);
    }
    return 0;
}

//&#x97F3;&#x9891;&#x89E3;&#x7801;&#x521D;&#x59CB;&#x5316;
void audio_decoder_prepare(MediaPlayer* player)
{
    //frame-&gt;16bit 44100 PCM &#x7EDF;&#x4E00;&#x97F3;&#x9891;&#x91C7;&#x6837;&#x683C;&#x5F0F;&#x4E0E;&#x91C7;&#x6837;&#x7387;
    player-&gt;swrContext = swr_alloc();
    //&#x8F93;&#x5165;&#x7684;&#x91C7;&#x6837;&#x683C;&#x5F0F;
    enum AVSampleFormat in_sample_fmt = player-&gt;audio_codec_context-&gt;sample_fmt;
    //&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x683C;&#x5F0F;16bit PCM
    player-&gt;out_sample_fmt = AV_SAMPLE_FMT_S16;
    //&#x8F93;&#x5165;&#x91C7;&#x6837;&#x7387;
    int in_sample_rate = player-&gt;audio_codec_context-&gt;sample_rate;
    //&#x8F93;&#x51FA;&#x91C7;&#x6837;&#x7387;
    player-&gt;out_sample_rate = in_sample_rate;
    //&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;2&#x4E2A;&#x58F0;&#x9053;&#xFF0C;&#x9ED8;&#x8BA4;&#x7ACB;&#x4F53;&#x58F0;stereo&#xFF09;
    uint64_t in_ch_layout = player-&gt;audio_codec_context-&gt;channel_layout;
    //&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x5E03;&#x5C40;&#xFF08;&#x7ACB;&#x4F53;&#x58F0;&#xFF09;
    uint64_t out_ch_layout = AV_CH_LAYOUT_STEREO;
    swr_alloc_set_opts(player-&gt;swrContext,
                       out_ch_layout, player-&gt;out_sample_fmt, player-&gt;out_sample_rate,
                       in_ch_layout, in_sample_fmt, in_sample_rate,
                       0, NULL);
    swr_init(player-&gt;swrContext);
    //&#x8F93;&#x51FA;&#x7684;&#x58F0;&#x9053;&#x4E2A;&#x6570;
    player-&gt;out_channel_nb = av_get_channel_layout_nb_channels(out_ch_layout);
}

//&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;
void audio_player_prepare(MediaPlayer* player, JNIEnv* env, jclass jthiz)
{
    jclass player_class = (*env)-&gt;GetObjectClass(env,jthiz);
    if(!player_class)
    {
       return ;
    }
    // &#x6839;&#x636E;&#x81EA;&#x5B9A;&#x4E49;&#x7684;java&#x65B9;&#x6CD5; createAudioTrack &#x83B7;&#x53D6; android &#x81EA;&#x5E26;&#x7684; AudioTrack &#x5BF9;&#x8C61;
    jmethodID audio_track_method = (*env)-&gt;GetMethodID(env,player_class,&quot;createAudioTrack&quot;,&quot;(II)Landroid/media/AudioTrack;&quot;);
    if(!audio_track_method)
    {
        return ;
    }
    jobject audio_track = (*env)-&gt;CallObjectMethod( env,jthiz,audio_track_method, player-&gt;out_sample_rate, player-&gt;out_channel_nb);
    //&#x8C03;&#x7528; AudioTrack &#x7684;play()&#x65B9;&#x6CD5;
    jclass audio_track_class = (*env)-&gt;GetObjectClass(env, audio_track);
    jmethodID audio_track_play_mid = (*env)-&gt;GetMethodID(env,audio_track_class,&quot;play&quot;,&quot;()V&quot;);
    (*env)-&gt;CallVoidMethod(env, audio_track, audio_track_play_mid);

    player-&gt;audio_track = (*env)-&gt;NewGlobalRef(env, audio_track);
    //&#x83B7;&#x53D6; AudioTrack &#x7684; write()&#x65B9;&#x6CD5;
    player-&gt;audio_track_write_mid = (*env)-&gt;GetMethodID(env,audio_track_class,&quot;write&quot;,&quot;([BII)I&quot;);
    //16bit 44100 PCM &#x6570;&#x636E;
    player-&gt;audio_buffer = (uint8_t *)av_malloc(MAX_AUDIO_FRAME_SIZE);
    //&#x89E3;&#x7801;&#x540E;&#x7684;&#x97F3;&#x9891;&#x6570;&#x636E;
    player-&gt;audio_frame = av_frame_alloc();
}

//&#x97F3;&#x9891;&#x89E3;&#x7801; + &#x64AD;&#x653E;
int decode_audio(MediaPlayer* player, AVPacket* packet)
{
    int got_frame = 0, ret;
    //&#x89E3;&#x7801;
    ret = avcodec_decode_audio4(player-&gt;audio_codec_context, player-&gt;audio_frame, &amp;got_frame, packet);
    if(ret &lt; 0)
    {
        return -1;
    }
    //&#x89E3;&#x7801;&#x4E00;&#x5E27;&#x6210;&#x529F;
    if(got_frame &gt; 0)
    {
        //&#x97F3;&#x9891;&#x683C;&#x5F0F;&#x8F6C;&#x6362;
        swr_convert(player-&gt;swrContext, &amp;player-&gt;audio_buffer,  MAX_AUDIO_FRAME_SIZE, (const uint8_t **)player-&gt;audio_frame-&gt;data, player-&gt;audio_frame-&gt;nb_samples);
        int out_buffer_size = av_samples_get_buffer_size(NULL,
                                                         player-&gt;out_channel_nb,
                                                         player-&gt;audio_frame-&gt;nb_samples,
                                                         player-&gt;out_sample_fmt,
                                                         1);

        //&#x97F3;&#x89C6;&#x9891;&#x5E27;&#x540C;&#x6B65;
        int64_t pts = packet-&gt;pts;
        // AV_NOPTS_VALUE  &#x65E0;&#x6548;&#x7684;pts &#x6807;&#x8BB0;
        if (pts != AV_NOPTS_VALUE)
        {
            AVStream *stream = player-&gt;format_context-&gt;streams[player-&gt;audio_stream_index];
            // av_rescale_q  AV_TIME_BASE_Q
            player-&gt;audio_clock = av_rescale_q(pts, stream-&gt;time_base, AV_TIME_BASE_Q);
            player_wait_for_frame(player, player-&gt;audio_clock + AUDIO_TIME_ADJUST_US);
        }

        if(javaVM != NULL)
        {
            JNIEnv * env;
            (*javaVM)-&gt;AttachCurrentThread(javaVM, &amp;env, NULL);
            jbyteArray audio_sample_array = (*env)-&gt;NewByteArray(env,out_buffer_size);
            jbyte* sample_byte_array = (*env)-&gt;GetByteArrayElements(env,audio_sample_array,NULL);
            memcpy(sample_byte_array, player-&gt;audio_buffer, (size_t) out_buffer_size);
            (*env)-&gt;ReleaseByteArrayElements(env,audio_sample_array,sample_byte_array,0);
            //&#x8C03;&#x7528;AudioTrack&#x7684;write&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x64AD;&#x653E;
            (*env)-&gt;CallIntMethod(env, player-&gt;audio_track, player-&gt;audio_track_write_mid, audio_sample_array,0,out_buffer_size);
            (*env)-&gt;DeleteLocalRef(env,audio_sample_array);
        }
    }
    if(javaVM != NULL)
    {
        (*javaVM)-&gt;DetachCurrentThread(javaVM);
    }
    return 0;
}

//&#x521D;&#x59CB;&#x5316;&#x961F;&#x5217;
void init_queue(MediaPlayer* player, int size)
{
    for (int i = 0; i &lt; 2; ++i)
    {
        AVPacketQueue* queue = queue_init(size);
        player-&gt;packets[i] = queue;
    }
}

//&#x91CA;&#x653E;&#x961F;&#x5217;
void delete_queue(MediaPlayer* player){
    int i;
    for (i = 0; i &lt; 2; ++i) {
        queue_free(player-&gt;packets[i]);
    }
}

//&#x8BFB;&#x53D6;AVPacket&#x7EBF;&#x7A0B;(&#x751F;&#x4EA7;&#x8005;) &#xFF0C; &#x83B7;&#x5F97;&#x89E3;&#x7801;&#x4E4B;&#x524D;&#x7684;&#x97F3;&#x9891;&#x6570;&#x636E;+&#x89C6;&#x9891;&#x6570;&#x636E;
void* write_packet_to_queue(void* arg)
{
    MediaPlayer* player = (MediaPlayer*)arg;
    AVPacket packet ;
    AVPacket *pkt = &amp;packet;
    for(;;)
    {
        int ret = av_read_frame(player-&gt;format_context, pkt);
        if(ret &lt; 0)
        {
            break;
        }
        if(pkt-&gt;stream_index == player-&gt;video_stream_index || pkt-&gt;stream_index == player-&gt;audio_stream_index)
        {
            // &#x5C06; &#x6BCF;&#x4E00;&#x5E27; &#x89E3;&#x7801;&#x524D;&#x7684; &#x6570;&#x636E; &#x5206;&#x522B;&#x5B58;&#x5230; &#x97F3;&#x9891; &#x548C;&#x89C6;&#x9891;&#x7684;&#x7F13;&#x51B2;&#x961F;&#x5217;&#x4E2D;
            AVPacketQueue *queue = player-&gt;packets[pkt-&gt;stream_index];
            pthread_mutex_lock(&amp;player-&gt;mutex);
            AVPacket* data = queue_push(queue, &amp;player-&gt;mutex, &amp;player-&gt;cond);
            pthread_mutex_unlock(&amp;player-&gt;mutex);
            *data = packet;
        }
    }
}


//&#x6839;&#x636E;&#x53C2;&#x6570; &#x89E3;&#x7801;&#x97F3;&#x9891; &#x6216; &#x89C6;&#x9891;
void* decode_func(void* arg)
{
    Decoder *decoder_data = (Decoder*)arg;
    MediaPlayer *player = decoder_data-&gt;player;
    int stream_index = decoder_data-&gt;stream_index;
    AVPacketQueue *queue = player-&gt;packets[stream_index];

    for(;;)
    {
        pthread_mutex_lock(&amp;player-&gt;mutex);
        AVPacket *packet = (AVPacket*)queue_pop(queue, &amp;player-&gt;mutex, &amp;player-&gt;cond);
        pthread_mutex_unlock(&amp;player-&gt;mutex);

        int ret = 0;
        if(stream_index == player-&gt;video_stream_index) {
            // &#x89E3;&#x7801; &#x89C6;&#x9891;
            ret = decode_video(player, packet);
        } else if(stream_index == player-&gt;audio_stream_index)
        {
            // &#x89E3;&#x7801; &#x97F3;&#x9891;
            ret = decode_audio(player, packet);
        }
        av_packet_unref(packet);
        if(ret &lt; 0)
        {
            break;
        }
    }
}


// &#x5BF9;&#x5916;&#x63A5;&#x53E3; &#xFF0C;&#x521D;&#x59CB;&#x5316; &#x64AD;&#x653E;&#x5668;
JNIEXPORT jint JNICALL Java_com_frank_ffmpeg_MediaPlayer_setup
        (JNIEnv * env, jclass clazz, jstring filePath, jobject surface)
{

    const char *file_name = (*env)-&gt;GetStringUTFChars(env, filePath, JNI_FALSE);
    player = malloc(sizeof(MediaPlayer));
    if(player == NULL)
    {
        return -1;
    }
    //&#x521D;&#x59CB;&#x5316;&#x8F93;&#x5165;&#x683C;&#x5F0F;&#x4E0A;&#x4E0B;&#x6587;
    int ret = init_input_format_context(player, file_name);
    if(ret &lt; 0)
    {
        return -1;
    }
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x89C6;&#x9891;&#x89E3;&#x7801;&#x5668;
    ret = init_condec_context(player);
    if(ret &lt; 0)
    {
        return -1;
    }
    //&#x521D;&#x59CB;&#x5316;&#x89C6;&#x9891;surface
    video_player_prepare( player, env, surface);
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x9891;&#x76F8;&#x5173;&#x53C2;&#x6570;
    audio_decoder_prepare(player);
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x9891;&#x64AD;&#x653E;&#x5668;
    audio_player_prepare(player, env,  clazz);
    //&#x521D;&#x59CB;&#x5316;&#x97F3;&#x89C6;&#x9891;packet&#x961F;&#x5217;
    init_queue(player, PACKET_SIZE);
    return 0;
}

// &#x5BF9;&#x5916;&#x63A5;&#x53E3; &#xFF0C; &#x64AD;&#x653E;&#x97F3;&#x89C6;&#x9891;
JNIEXPORT jint JNICALL Java_com_frank_ffmpeg_MediaPlayer_play (JNIEnv * env, jclass clazz)
{
    pthread_mutex_init(&amp;player-&gt;mutex, NULL);
    pthread_cond_init(&amp;player-&gt;cond, NULL);

    // &#x83B7;&#x5F97;&#x89E3;&#x7801;&#x524D;&#x7684; &#x97F3;&#x9891;&#x6570;&#x636E; &#x548C;&#x89C6;&#x9891;&#x6570;&#x636E; &#xFF0C; &#x5B50;&#x7EBF;&#x7A0B;
    pthread_create(&amp;player-&gt;write_thread, NULL, write_packet_to_queue, (void*)player);
    sleep(1);
    player-&gt;start_time = 0;

    //&#x89E3;&#x7801;&#x89C6;&#x9891; &#xFF0C; &#x5B50;&#x7EBF;&#x7A0B;
    Decoder data1 = {player, player-&gt;video_stream_index} ;
    Decoder *decoder_data1 = &amp;data1;
    pthread_create(&amp;player-&gt;video_thread, NULL, decode_func, (void*)decoder_data1);

    // &#x89E3;&#x7801;&#x97F3;&#x9891; &#xFF0C; &#x5B50;&#x7EBF;&#x7A0B;
    Decoder data2 = {player, player-&gt;audio_stream_index} ;
    Decoder *decoder_data2 = &amp;data2;
    pthread_create(&amp;player-&gt;audio_thread,NULL,decode_func,(void*)decoder_data2);

    pthread_join(player-&gt;write_thread, NULL);
    pthread_join(player-&gt;video_thread, NULL);
    pthread_join(player-&gt;audio_thread, NULL);

    return 0;
}

// &#x91CA;&#x653E;&#x8D44;&#x6E90;
JNIEXPORT void JNICALL Java_com_frank_ffmpeg_MediaPlayer_release
        (JNIEnv * env, jclass clazz)
{
    //&#x91CA;&#x653E;&#x5185;&#x5B58;&#x4EE5;&#x53CA;&#x5173;&#x95ED;&#x6587;&#x4EF6;
    free(player-&gt;audio_track);
    free(player-&gt;audio_track_write_mid);
    av_free(player-&gt;buffer);
    av_free(player-&gt;rgba_frame);
    av_free(player-&gt;yuv_frame);
    av_free(player-&gt;audio_buffer);
    av_free(player-&gt;audio_frame);
    avcodec_close(player-&gt;video_codec_context);
    avcodec_close(player-&gt;audio_codec_context);
    avformat_close_input(&amp;player-&gt;format_context);
    ANativeWindow_release(player-&gt;native_window);
    delete_queue(player);
    pthread_cond_destroy(&amp;player-&gt;cond);
    pthread_mutex_destroy(&amp;player-&gt;mutex);
    free(player);
    (*javaVM)-&gt;DestroyJavaVM(javaVM);
}
</code></pre>
<pre><code class="lang-text">public AudioTrack createAudioTrack(int sampleRate, int channels){
    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    int channelConfig;
    if(channels == 1){
        channelConfig = android.media.AudioFormat.CHANNEL_OUT_MONO;
    }else if(channels == 2){
        channelConfig = android.media.AudioFormat.CHANNEL_OUT_STEREO;
    }else{
        channelConfig = android.media.AudioFormat.CHANNEL_OUT_STEREO;
    }

    //  &#x8FD4;&#x56DE;&#x97F3;&#x8F68;&#x6240;&#x9700;&#x7684;&#x4F30;&#x8BA1;&#x6700;&#x5C0F;&#x7F13;&#x51B2;&#x533A;&#x5927;&#x5C0F;    
    int bufferSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);

    return new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, channelConfig, audioFormat,
            bufferSizeInBytes, AudioTrack.MODE_STREAM);
}
</code></pre>
<h2 id="ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;"><a name="ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;" class="anchor-navigation-ex-anchor" href="#ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;"><i class="fa fa-link" aria-hidden="true"></i></a>2.11. ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;</h2>
<p><a href="https://download.csdn.net/user/dengpanwen/uploads" target="_blank">&#x6240;&#x9700;so</a></p>
<pre><code class="lang-text">include &lt;jni.h&gt;
include &lt;string&gt;
include &lt;android/bitmap.h&gt;
include &lt;android/native_window.h&gt;
include &lt;android/native_window_jni.h&gt;

extern &quot;C&quot; {
include &lt;libavcodec/avcodec.h&gt;
include &lt;libswscale/swscale.h&gt;
include &lt;libavformat/avformat.h&gt;
include &lt;libavutil/avutil.h&gt;
include &lt;libavutil/frame.h&gt;
include &lt;libavdevice/avdevice.h&gt;
include &lt;libavfilter/avfilter.h&gt;
include &quot;libswresample/swresample.h&quot;
include &quot;libavutil/opt.h&quot;
include &quot;libavutil/imgutils.h&quot;
}

static AVPacket *pPacket;
static AVFrame *pAvFrame, *pFrameBGR;
static AVCodecContext *pCodecCtx;
struct SwsContext *pImgConvertCtx;
static AVFormatContext *pFormatCtx;
ANativeWindow* nativeWindow;
ANativeWindow_Buffer windowBuffer;
uint8_t *v_out_buffer;
bool stop;

extern &quot;C&quot;
JNIEXPORT jint JNICALL
Java_com_nazhi_testlive555_FfmpegUtils_openVideo(JNIEnv *env, jclass type, jstring url,
                                                 jobject surface) {
    stop = false;
    // &#x7248;&#x672C;&#x517C;&#x5BB9;
    if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55, 28, 1)
    define av_frame_alloc  avcodec_alloc_frame
    endif

    pAvFrame = av_frame_alloc();
    pFrameBGR = av_frame_alloc();

    char input_str[500]={0};
    // &#x521D;&#x59CB;&#x5316;rtsp&#x5730;&#x5740;
    sprintf(input_str, &quot;%s&quot;, env-&gt;GetStringUTFChars(url, NULL));
    //&#x7ED1;&#x5B9A;surface &#x548C; ANativeWindow
    nativeWindow = ANativeWindow_fromSurface(env, surface);
    if (0 == nativeWindow){
        return -1;
    }

    //&#x6CE8;&#x518C;&#x7F16;&#x89E3;&#x7801;&#x5668;
    avcodec_register_all();
    //&#x6CE8;&#x518C;&#x6240;&#x6709;&#x7EC4;&#x4EF6;
    av_register_all();
    // &#x521D;&#x59CB;&#x5316;&#x7F51;&#x7EDC;&#x5E93;
    avformat_network_init();
    // &#x6CE8;&#x518C;&#x8BBE;&#x5907;
    avdevice_register_all();

    pFormatCtx = avformat_alloc_context();
    // &#x6253;&#x5F00;rtsp&#x6D41;
    if (avformat_open_input(&amp;pFormatCtx, input_str, NULL, NULL) &lt; 0)
    {
        return 1;
    }
    // &#x83B7;&#x53D6;&#x97F3;&#x9891;&#x4FE1;&#x606F;
    avformat_find_stream_info(pFormatCtx, NULL);

    int videoIndex = -1;
    //&#x904D;&#x5386;&#x627E;&#x5230;&#x7684;&#x89C6;&#x97F3;&#x9891;&#x6D41;
    for (unsigned int i = 0; i &lt; pFormatCtx-&gt;nb_streams; i++)
    {
        // &#x627E;&#x5230;&#x89C6;&#x9891;&#x6D41;
        if (pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO) {
            videoIndex = i;
            break;
        }
    }

    // &#x83B7;&#x5F97;&#x89E3;&#x7801;&#x9700;&#x8981;&#x7684;&#x76F8;&#x5173;&#x4FE1;&#x606F;
    pCodecCtx = pFormatCtx-&gt;streams[videoIndex]-&gt;codec;

    // &#x83B7;&#x5F97; &#x7F16;&#x7801;&#x5668;&#x76F8;&#x5173;&#x4FE1;&#x606F;
    AVCodec *pCodec = avcodec_find_decoder(pCodecCtx-&gt;codec_id);
    //&#x4E3A;&#x5404;&#x79CD;&#x7ED3;&#x6784;&#x4F53;&#x5206;&#x914D;&#x5185;&#x5B58; &#x548C;&#x4E00;&#x4E9B;&#x5FC5;&#x8981;&#x7684;&#x68C0;&#x67E5;
    avcodec_open2(pCodecCtx, pCodec, NULL);

    int width = pCodecCtx-&gt;width;
    int height = pCodecCtx-&gt;height;

    // &#x8BA1;&#x7B97;&#x7F13;&#x51B2;&#x533A;&#x586B;&#x5145;&#x6240;&#x9700;&#x7684;&#x5927;&#x5C0F;
    int numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGBA, width, height, 1);
    v_out_buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));

    // &#x7ED9;&#x50CF;&#x7D20;&#x6570;&#x636E;&#x5206;&#x914D;&#x7A7A;&#x95F4;
    av_image_fill_arrays(pFrameBGR-&gt;data, pFrameBGR-&gt;linesize, v_out_buffer, AV_PIX_FMT_RGBA, width, height, 1);

    //SwsContext &#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x89C6;&#x9891;&#x56FE;&#x50CF;&#x7684;&#x8F6C;&#x6362; &#xFF0C;sws_getContext&#x521D;&#x59CB;&#x5316;
    pImgConvertCtx = sws_getContext(
            pCodecCtx-&gt;width,             //&#x539F;&#x59CB;&#x5BBD;&#x5EA6;
            pCodecCtx-&gt;height,            //&#x539F;&#x59CB;&#x9AD8;&#x5EA6;
            pCodecCtx-&gt;pix_fmt,           //&#x539F;&#x59CB;&#x683C;&#x5F0F;
            pCodecCtx-&gt;width,             //&#x76EE;&#x6807;&#x5BBD;&#x5EA6;
            pCodecCtx-&gt;height,            //&#x76EE;&#x6807;&#x9AD8;&#x5EA6;
            AV_PIX_FMT_RGBA,              //&#x76EE;&#x6807;&#x683C;&#x5F0F;
            SWS_BICUBIC,                  //&#x7B97;&#x6CD5;&#x7C7B;&#x578B;
            NULL,
            NULL,
            NULL);

    // &#x8BBE;&#x7F6E; ANativeWindow &#x7684;&#x7F13;&#x5B58;&#x5927;&#x5C0F; ,&#x8FD4;&#x56DE;&#x503C; &lt; 0 &#x8868;&#x793A;&#x5931;&#x8D25;
    if ( ANativeWindow_setBuffersGeometry(nativeWindow,width,height,WINDOW_FORMAT_RGBA_8888) &lt;0 ){
        ANativeWindow_release(nativeWindow);
        return -1;
    }


    // &#x7ED9; AVPacket &#x5206;&#x914D;&#x5185;&#x5B58;
    pPacket = (AVPacket*)av_malloc(sizeof(AVPacket));

    while (!stop) {
        // &#x83B7;&#x5F97;&#x4E00;&#x5E27;&#x89C6;&#x9891;&#x7684;&#x538B;&#x7F29;&#x6570;&#x636E;
        if (av_read_frame(pFormatCtx, pPacket) &gt;= 0) {
            if ((pPacket)-&gt;stream_index != videoIndex) {
                continue;
            }

            int gotPicCount = 0;
            //&#x89E3;&#x7801; ,  &#x89E3;&#x7801;&#x5931;&#x8D25; gotPicCount &#x8FD4;&#x56DE;&#x503C;&#x4E3A;0
            avcodec_decode_video2(pCodecCtx, pAvFrame, &amp;gotPicCount, pPacket);
            if (gotPicCount != 0) {
                // &#x8F6C;&#x6362;&#x50CF;&#x7D20;
                sws_scale(
                        pImgConvertCtx,
                        (const uint8_t *const *) pAvFrame-&gt;data,
                        pAvFrame-&gt;linesize,
                        0,
                        pCodecCtx-&gt;height,
                        pFrameBGR-&gt;data,
                        pFrameBGR-&gt;linesize);

                // &#x9501;&#x5B9A; ANativeWindow , &#x8FD4;&#x56DE;&#x503C; &#x5C0F;&#x4E8E;0 &#x4EE3;&#x8868;&#x5931;&#x8D25;
                if (ANativeWindow_lock(nativeWindow, &amp;windowBuffer, NULL) &gt;= 0)
                {
                    uint8_t *dst = (uint8_t *) windowBuffer.bits;
                    for (int h = 0; h &lt; height; h++)
                    {
                        // &#x5C06;&#x6570;&#x636E;&#x62F7;&#x8D1D;&#x5230; ANativeWindow &#x4EE5;&#x4FBF;&#x89E3;&#x7801;&#x3001;&#x663E;&#x793A;
                        memcpy(dst + h * windowBuffer.stride * 4,
                               v_out_buffer + h * pFrameBGR-&gt;linesize[0],
                               pFrameBGR-&gt;linesize[0]);
                    }
                    // &#x91CA;&#x653E;&#x9501;&#x5B9A; ANativeWindow
                    ANativeWindow_unlockAndPost(nativeWindow);
                }
            }
        }
        // &#x91CD;&#x7F6E; AVPacket
        av_packet_unref(pPacket);
    }
    // &#x91CA;&#x653E; SwsContext
    sws_freeContext(pImgConvertCtx);
    //&#x91CA;&#x653E;
    av_free(pPacket);
    av_free(pFrameBGR);
    // &#x5173;&#x95ED; AVCodecContext
    avcodec_close(pCodecCtx);
    // &#x5173;&#x95ED; AVFormatContext
    avformat_close_input(&amp;pFormatCtx);
    return 1;
}


extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_nazhi_testlive555_FfmpegUtils_stop(JNIEnv *env, jclass type) {
    stop = true;
}
</code></pre>
<footer class="page-footer"><span class="copyright">( no Copyright&#xFF0C;enjoy youself ! ) all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">The file was updated at :
2022-04-04 10:49:02
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="音视频第三方库.html" class="navigation navigation-prev " aria-label="Previous page: 音视频第三方库">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../server/服务器部分.html" class="navigation navigation-next " aria-label="Next page: 服务器部分">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"相关代码","level":"1.17.7","depth":2,"next":{"title":"服务器部分","level":"1.18","depth":1,"path":"chinese/server/服务器部分.md","ref":"chinese/server/服务器部分.md","articles":[]},"previous":{"title":"音视频第三方库","level":"1.17.6","depth":2,"path":"chinese/native/音视频第三方库.md","ref":"chinese/native/音视频第三方库.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","fontsettings","tbfed-pagefooter","local-video","splitter","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"( no Copyright，enjoy youself ! )","modify_label":"The file was updated at :","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/native/相关代码.md","mtime":"2022-04-04T02:49:02.768Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-04T03:47:09.782Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

